ng-lightning-查找时未定义数据对象 [英] ng-lightning - data object is undefined on lookup
本文介绍了ng-lightning-查找时未定义数据对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Lookup组件,但收到一个错误消息,即我的数据对象未定义,因此无法.filter().代码如下:
I'm working with the Lookup component and am getting an error that my data object is undefined and thus cannot .filter(). Code is below:
getAllAccounts() {
this._quickAddService.getAllAccounts()
.subscribe(
accounts => this.getAllAccountsFinished(accounts),
error => this.errorMessage = <any>error);
}
getAllAccountsFinished(accounts:any) {
this.accounts = accounts;
console.log(this.accounts);
this.hideSpinner();
}
ngOnInit(){
this.getAllAccounts();
}
lookup(query: string): Account[] {
if (!query) {
return null;
}
return this.accounts.filter((item) => item.name.toLowerCase().indexOf(query.toLowerCase())>-1);
}
该console.log显示服务完成返回后,数据已正确绑定.但是,当对输入触发查找时,this.accounts是未定义的.
that console.log is showing that the data is bound properly once the service finishes returning. However when lookup is fired on input this.accounts is undefined.
推荐答案
@bekos在吉特.需要向组件构造函数添加绑定:
Answered by @bekos on the Gitter. Need to add binding to component constructor:
constructor(elementRef:ElementRef, private _quickAddService:QuickAddService) {
this.visible = true;
this.lookup = this.lookup.bind(this);
}
这篇关于ng-lightning-查找时未定义数据对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文