我正在尝试在我的 Angular2 项目中使用bootstrap-tagsinput库。该库是使用package.json
文件安装的:
"dependencies": {
...
"bootstrap-tagsinput": "^0.7.1",
...
}
现在我有一个bootstrap-tagsinput
文件夹node_modules
。我想在特定组件中使用 tagsinput。我看到目录中有一个bootstrap-tagsinput-angular.js
文件node_modules/bootstrap-tagsinput/dist
,但我无法正确使用它。
我是否应该在我的 index.html 中添加 JS 文件,以便 bootstrap-tagsinput 可用于所有组件?或者有没有办法在需要的地方导入它?
换句话说,有没有办法做这样的事情:
mycomponent.component.html:
<input type="text" value="Amsterdam,Washington,Sydney,Beijing,Cairo" data-role="tagsinput"/>
mycomponent.component.ts:
import {Component, AfterViewInit} from '@angular/core';
import {TagsInputComponents} from 'bootstrap-tagsinput'; // Something like that?!?
@Component({
...
})
export class MyComponentComponent implements AfterViewInit {
ngAfterViewInit():any {
$('input').tagsinput('refresh');
}
}
非常感谢你的帮助!