我有一个
angular5-data-table
我正在实现的模块。我可以使用它的所有功能。另外,我想在上面添加一个搜索功能。我添加了下面的代码(html和typescript)并开始接收
ERROR TypeError: Cannot read property 'slice' of undefined
错误。
我的搜索HTML是:
<input type="text" class="form-control input-md" placeholder="Search by full name" #query (keyup)="searchMember(query.value)" [(ngModel)]="filter.name">
这背后的密码
searchMember(query.value)
是:
searchMember(query: string) {
let members = this.allMembers;
if (this.filter.firstName) {
members = members.filter(o => o.firstName.toLowerCase().includes(query.toLowerCase()));
}
this.members = members;
this.initializeTable(this.members);
console.log(members);
}
这里是
initializeTable()
:
private initializeTable(members: Member[]) {
this.tableResource = new DataTableResource(members);
this.tableResource.query({ offset: 0 }).then(items => this.items = items);
this.tableResource.count().then(count => this.itemCount = count);
}
最后,这里是初始化:
filter: any = {};
tableResource: DataTableResource<Member>;
allMembers: Member[];
我不确定我是否理解这个错误。有什么想法吗?