What's the proper way for loading jQuery functions in Angular 2?
I've added my jQuery to ngAfterViewInit. It works fine for one route, but if I navigate to another one (e.g. from id: 1 to id: 2), it doesn't work for the second one (I'm using the same component for both).
It works using ngAfterViewChecked but, then, the function is executed multiple times (after every change in the view).
This is my jQuery function:
$('.chips').on('chip.add', (e, chip) => {
console.log(e, chip);
});
constructorandngAfterViewInitaren't firingIt works using ngAfterViewChecked but, then, the function is executed multiple times (after every change in the view)When you say$(.chips)you only refer to the already rendered elements. Any new element will require you to add it again and that is how it is supposed to work.