kuuurt13 / ng-block-ui

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

BlockUI directive not working in Angular 18 #275

Open ShoulderMonkey opened 2 months ago

ShoulderMonkey commented 2 months ago

I'm upgrading to angular 18 from angular 17 in one of my projects and i'm getting error where using

@BlockUI()blockUI!: NgBlockUI

gives error:

TypeError: Cannot read properties of undefined (reading 'start')

had to switch to using the BlockUIService instead and specifying name in selector like so:

`<block-ui [template]="foregroundSpinner" name="test" >

constructor( private blockUI: BlockUIService ){

  }

this.blockUI.start('test') `

eheck-is commented 2 months ago

FWIW, I have the same problem in one Angular app, but not in another. I found that in the app where the problem occurs, the decorator assigns the BlockUI instance to the component's prototype but the component object has its own property with an "undefined" value. In the app where everything works, the BlockUI instance is still set into the prototype but the component object itself doesn't have the property and is getting the prototype value.

eheck-is commented 2 months ago

... and a possible workaround for that is to set "useDefineForClassFields" to false in typescript options for the time being