kuuurt13 / ng-block-ui

Block UI Loader/Spinner for Angular
MIT License
145 stars 25 forks source link

BlockUI directive always undefined when included within a library (Angular 16) #270

Closed VincenzoManto closed 3 months ago

VincenzoManto commented 1 year ago

Issue with ng-block-ui in Angular 16

Description

Using ng-block-ui@4.0.1 in Angular 16 works as expected when included within an application project, but it fails in libraries.

We include ng-block-ui as follows:

@BlockUI('content-wrapper') blockBody: NgBlockUI;
<div *blockUI="'content-wrapper'" class="content-wrapper"></div>

The spinner displays properly when used within an application, but when the library is compiled in ES2022 and included in an application, it always appears as undefined, regardless of where or when it is checked (in ngOnInit, ngAfterViewInit, constructor, and even in asynchronous subscribe), long after the template rendering.

Environment

Package Versions

Steps to Reproduce

  1. Include ng-block-ui in an Angular library project.
  2. Use @BlockUI decorator and *blockUI directive within library components.
  3. Include the library in an Angular application.
  4. Observe that the spinner always appears as undefined.

Expected Behavior

The ng-block-ui spinner should function correctly in both library and application projects when using the same code.

Additional Information

Please let me know if you need any additional information to help resolve this issue.

dpw-dev commented 3 months ago

@VincenzoManto were you able to resolve this? I am facing the similar issue.

VincenzoManto commented 3 months ago

@dpw-dev yes, we opted for using this.block.start('content-wrapper'); and this.block.stop('content-wrapper');, directly controlling the spinner in the TS and ensuring to do it after the view content is initialized (so after the AfterViewInit event)

dpw-dev commented 3 months ago

Hey @VincenzoManto thank you for the suggestion. However, when I tried implementing it, I am still facing the issue. Is the below div on the app level or in the component inside the library?.

<div *blockUI="'content-wrapper'" class="content-wrapper"></div>

If possible could you share a sample project structure?

Appreciate the help.

Thanks

VincenzoManto commented 3 months ago

<div *blockUI="'content-wrapper'" class="content-wrapper"></div> is at the HTML component level in the library. We suggest to remove this directive and directly use the this.block.start('content-wrapper'); and this.block.start('content-wrapper'); in the component TS to control the block tag wherever you need in the logic class

dpw-dev commented 3 months ago

Thanks @VincenzoManto. That works.