我正在做一个项目,我想在 ng-select 中创建一个自定义功能,以便在 ng-select 中输入文本时,它将它附加到绑定(bind)项并将其添加为多选。
http://embed.plnkr.co/GLuyC0jpIdiEXB6R4FIa/preview
这是 Angular 6 中所需的确切实现
我正在使用 angular v6.0
在 Angular 5 中是否还有其他方法可以实现,如提到的 plunker 所示??
对不起,如果有问题的话。 因为我是 Angular 的新手。
提前致谢。
最佳答案
我找到的唯一解决方案是访问 ng-select
children 。
我的 html:
<ng-select [items]="places"
bindLabel="name"
[(ngModel)]="selected" dropdownPosition="bottom" #ngselect>
<ng-template ng-option-tmp let-item="item" let-index="index">
<b>{{item}}</b>
</ng-template>
</ng-select>
ngselect
- NGSelectComponent
this.myselect.element
- 使用 HTMLElement,在 child 中我们正在寻找我们的 <input>
@ViewChild('myngselect') myselect;
myMethod() {
const input = this.myselect.element.children[0].children[0].children[1].children[0];
}
关于javascript - 想要以 Angular 6 访问 ng-select 中的输入元素以获得它的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50851013/