我正在使用此包https://www.npmjs.com/package/angular2-mentions。 所以我的代碼是這樣的:Angular 2提到:如何在api調用後更新數組綁定到指令
.ts file :
ngOnInit():void {
this.items.push("temp Name")
let __this = this
this._userService.getAll(1).subscribe(res => {
res.users.forEach(function (a,b) {
__this.items.push(a)
})
console.log(__this.items)
})
}
.html文件:
<input type="text" [mention]="items" >
該陣列被更新並具有從API的數據,但該指令[提及]被綁定到舊數組包含值在開始時靜態初始化!
你覺得答案有幫助嗎? – krzysztofla