我正在使用@ng-select/ng-select
.html 文件
<ng-select [items]="_Customers"
[addTag]="addTagPromise"
[bindLabel]="'name'"
[(ngModel)]="selectedCustomer">
</ng-select>
addTag正在工作,但 无法访问已定义值内的addTagPromise 函数
ts文件
_Customers: any[] = [];
companies = ['company one', 'company Two', 'company three'];
selectedCustomer;
ngOnInit() {
this.companies.forEach((c, i) => {
this._Customers.push({ id: i, name: c });
});
}
addTagPromise(name) {
console.log(this._Customers);
return new Promise((resolve) => {
setTimeout(() => {
resolve({ id: 5, name: name, valid: true });
}, 1000);
})
}
打印的日志未定义
如何访问 addTagPromise 函数中已定义的值?