昨天在學習angular4框架的時候,通過npm安裝bootstrap插件,但是在啓動的時候ng serve會在控制檯輸出錯誤。當bootstrap.css從angular-cli.json中移除之後, ng serve就可以正常啓動。推斷的話是angular環境的問題,在將Ide(webstrom)升級到2017.2同時升級了TypeScript的版本後,之前在編輯app.component.ts
時jQuery的$
不能被識別的問題解決了。但是在通過Ng serve啓動的時候還是報同樣的錯。
之前angular-cli.json的配置爲:
在StackOverflow上看到有人解決了這樣的問題,Bootstrap 4 not working with Angular 2 app
具體的文章鏈接爲: https://stackoverflow.com/que...
文章的大概意思是說,通過npm install bootstrap --save
這種方式已經不推薦使用,應該轉而使用npm install [email protected] popper.js jquery --save
並且在angular-cli.json中的配置如下:
"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"
],
按照這種方式重新安裝bootstrap的插件之後,重啓服務Ng serve就可以正常訪問。如果你也有遇到這樣的問題,希望可以幫助到你。