简体   繁体   中英

Applying a dependency with javascript to Angular 2 such as bootstrap, foundation or jquery

creating this Angular 2 project I am trying to add other dependencies to the global project that incorporate js files and css files.

The css files work fine... but the javascript files seem to not to apply correctly at all.

I am attempting to do this in the root index.html file.

In the dom everything appears to be correct and there are no warning, errors or conflicts which leads me to believe it is an injection issue.

Interestingly if I apply the html to the index.html everything works fine... but adding it to any component makes it useless.

There is something I am probably doing wrong.

You need to bootstrap your external libraries' code when the component bootstraps. For example, if you are using the bootstrap collapse on some menu items in a component, you need to call $(class).collapse() in the ngOnInit of that component( or anywhere else in the lifecycle of the component ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM