我有一个剑道下拉菜单,当用户在搜索框中输入 3 个字母时,我想通过 API 调用将数据加载到下拉菜单中。
我试过这种方法。但它没有得到适当的。有人可以给我适当的解决方案吗?
.ts
public nameList: any[] = [];
modelChange(searchTerm: any){
if(searchTerm !== ""){
this.getnameList(searchTerm);
}
}
getNameList(searchTerm:any){
this.compsService.getNames(searchTerm).subscribe((res) => {
res.data.forEach((element:any) => {
this.nameList = element.name;
});
});
}
.html
<kendo-dropdownlist [data]="nameList " [filterable]="true" textField="companyName"
valueField="partyRoleId" formControlName="name" [valuePrimitive]="true" (ngModelChange)="modelChange($event)">
</kendo-dropdownlist>