我正在尝试使用 bootstrap-tagsinput我的 Angular2 项目中的库。该库使用 package.json 文件安装:
"dependencies": {
...
"bootstrap-tagsinput": "^0.7.1",
...
}
现在我在 node_modules 中有一个 bootstrap-tagsinput 文件夹。我想在特定组件中使用 tagsinput。我看到 node_modules/bootstrap-tagsinput/dist 目录下有一个 bootstrap-tagsinput-angular.js 文件,但我无法正确使用它。
我是否应该在我的 index.html 中添加 JS 文件,以便所有组件都可以使用 bootstrap-tagsinput?或者有没有办法在需要的地方导入它?
换句话说,有没有办法做这样的事情:
我的组件.component.html:
<input type="text" value="Amsterdam,Washington,Sydney,Beijing,Cairo" data-role="tagsinput"/>
我的组件.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');
}
}
非常感谢您的帮助!
最佳答案
如果您使用 angular,我可以看到将 bootstrap-tags-input 与 angular batter 一起使用时会出现一些问题。
请查看更多详细信息:ngTagsInput , demo
关于javascript - Angular 2 : how to use bootstrap-tagsinput properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38551251/