我在 Angular 4 中使用 ngx-chips,如果所有输入都是字符串,它工作正常。如果我在任何输入中输入任何整数,例如 mh1,它不会显示下拉列表。
这是我的组件代码:
public requestAutocompleteItems = (text: any): Observable<Response> => {
let api_base_url = environment.api_end_point+'?json=1&entity=ttp&action=fetchteacherlist&api_key='+environment.default_api_key+'&key='+environment.key+'';
const url = api_base_url;
return this.http
.post(url, '{"teacher_code" : "'+text+'", "entity_id" : "'+localStorage.getItem('my_aol_entity_id')+'", "ttp_lead_id" : "'+localStorage.getItem('my_aol_ttp_lead_id')+'", "source" : "1"}')
.map(data => data.json().result.map(item => item));
}
我的 HTML 代码:
<tag-input name="p_teacher_id" id="p_teacher_id" [ngClass]="'tag-select'" theme='bootstrap' [(ngModel)]="p_teacher_name"
[placeholder]="'Teacher Code'" [onTextChangeDebounce]="500" [secondaryPlaceholder]="'Teacher Code'" [onlyFromAutocomplete]="true"
[maxItems]="1" (onAdd)="onSelectedTeacher($event,1)" (onRemove)="onItemRemoved($event,1)">
<tag-input-dropdown [autocompleteObservable]="requestAutocompleteItems">
<ng-template let-item="item" let-index="index">
{{ item.display }}
</ng-template>
</tag-input-dropdown>
</tag-input>
api响应:
{"success":true,"message":"Recommending teacher list.","result":[{"display":"Hiremath Mrugendra Chanabsayya","value":"2"}]}