如何在angular-cli项目中解决上述错误
我正在使用bootstrap标签输入ui
我的angular-cli.json文件
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.css",
"../node_modules/primeng/resources/themes/omega/theme.css",
"assets/plugins/tags_input/bootstrap-tagsinput.css",
"styles.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/jquery-sparkline/jquery.sparkline.js",
"../src/assets/plugins/tags_input/bootstrap-tagsinput.js"
]
app.controller.ts文件
import * as $ from 'jquery';
ngAfterViewInit() {
$('.tagsinput').tagsinput({
tagClass: 'label label-primary'
});
}
app.controller.html
<input class="tagsinput form-control" type="text" value="Amsterdam,Washington,Sydney,Beijing,Cairo"/>
我正面临这个错误
ERROR TypeError: __WEBPACK_IMPORTED_MODULE_5_jquery__(...).tagsinput is not a function
at advisorCreateEditComponent.webpackJsonp.../../../../../src/app/advisor/advisor-create-edit.component.ts.advisorCreateEditComponent.ngAfterViewInit (main.bundle.js:104)
at callProviderLifecycles (vendor.bundle.js:169756)
at callElementProvidersLifecycles (vendor.bundle.js:169727)
at callLifecycleHooksChildrenFirst (vendor.bundle.js:169711)
at checkAndUpdateView (vendor.bundle.js:170839)
at callViewAction (vendor.bundle.js:171179)
at execEmbeddedViewsAction (vendor.bundle.js:171137)
at checkAndUpdateView (vendor.bundle.js:170832)
at callViewAction (vendor.bundle.js:171179)
at execComponentViewsAction (vendor.bundle.js:171111)
答案 0 :(得分:1)
在controller.ts文件中更改jsut
declare var $: any;