I am trying to use the jQuery plugin which replaces the default scroll bar inside some dynamic elements in Angular 2.
These elements are created using the ngFor loop, that is, I cannot attach jQuery events to the elements it creates.
The application, at some point, mutates the Observable object, which is processed internally by ngFor to display the view.
Now I would like to know when Angular will finish drawing my elements so that I can run the jQuery plugin.
- I do not want to include javascript in the HTML template.
- I do not want to use
ngAfterViewInit because this hook is triggered too many times - I do not want to implement a solution based on setTimeout (I think it is not reliable)
I found a solution using the following custom Pipe : at the end of the ngFor loop in the template, I write:
{{i | FireStoreEventPipe:'EVENT_TO_BE_FIRED'}}
Where the FireStoreEventPipe is something like:
transform(obj: any, args:any[]) { var event = args[0];
But this decision does not satisfy me.
Any suggestion for a better way?
thanks
source share