chrisP10
chrisP10

Reputation: 1

How to load jQuery scripts in every component?

I'm building a single page application using Angular2 and the Limitless layout. However, there is an app.js file in the theme that contains all the jQuery functionality. I have loaded it in the index.html but the jQuery only works when I refresh the page.

How can I modify the app.js to make the jQuery function inside run in every component?

Upvotes: 0

Views: 375

Answers (2)

Fabrizio Caldarelli
Fabrizio Caldarelli

Reputation: 3008

Before the Component Decorator, use

// You can use $ to refer to jQuery inside the code
declare var $ : any;

@Component({
  selector: 'my-selector',
  providers: []
})

Upvotes: 0

anshuVersatile
anshuVersatile

Reputation: 2068

create function in app.js ie.

function executeEveryCompo(){
      console.log('Something');
}

and in every component AfterviewInit add

ngAfterviewInit(){
     executeEveryCompo();
}

dont forget to add declare var executeEveryCompo:any; at the top of component

Upvotes: 0

Related Questions