admin管理员组文章数量:1279234
I'm trying to launch training project that requires Popper.Js in its features. However, it doesn't seem to let me just start to use Popper.Js.
According to Bootstrap's docs I start Popper.Js by
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
I use it in main ponent in ngOnInit
. However, it doesn't work. The error occurs "Property 'tooltip' does not exist on type 'JQuery'". I imported jquery and bootstrap bundle file. Types for all the libraries are installed.
I also tried the pure "popper.js" instead of bootstrap.bundle.js. But the same error occurs. Bootstrap.bundle.js(includes bootstrap and popper.js in right order) and jquery are imported in angular-cli.json.
I'm trying to launch training project that requires Popper.Js in its features. However, it doesn't seem to let me just start to use Popper.Js.
According to Bootstrap's docs I start Popper.Js by
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
I use it in main ponent in ngOnInit
. However, it doesn't work. The error occurs "Property 'tooltip' does not exist on type 'JQuery'". I imported jquery and bootstrap bundle file. Types for all the libraries are installed.
I also tried the pure "popper.js" instead of bootstrap.bundle.js. But the same error occurs. Bootstrap.bundle.js(includes bootstrap and popper.js in right order) and jquery are imported in angular-cli.json.
Share Improve this question edited Feb 19, 2018 at 16:21 Melchia 24.3k23 gold badges108 silver badges129 bronze badges asked Dec 30, 2017 at 22:31 SergeySergey 7,68214 gold badges47 silver badges97 bronze badges1 Answer
Reset to default 12Run the following mand to install bootstrap jquery & popper.js:
npm install [email protected] popper.js jquery --save
In angular-cli.json add these lines:
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/popper.js/dist/popper.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.min.js"
],
In your page.ts Add:
declare var $;
Edit:
Not all JavaScript libraries/frameworks have TypeScript declaration files. On the other hand, we might want to use libraries/frameworks in our TypeScript files without getting pilation errors. One solution is to use the declare keyword. The declare keyword is used for ambient declarations where you want to define a variable that may not have originated from a TypeScript file.
本文标签: javascriptAngular 5PopperJSStack Overflow
版权声明:本文标题:javascript - Angular 5 + Popper.JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741250304a2365665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论