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);
});

Plunker

share|improve this question
    
Could you demonstrate it on a plunker? – yurzui 1 hour ago
    
Here's a Plunker. – drbishop 22 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.