這裏是一個簡單的問題,我找不到解決方案。我在輸入中有一個typeahead指令讓用戶選擇一個類別(類別數組示例 - > [{id:1as1d,name:'some category'},...]ngx-bootstrap typeahead FormControl angular 2
如何將id值設置爲FormControl字段(它將出現在提交的表單中)並在輸入上顯示名稱(在用戶選擇時將在輸入中顯示該名稱)?有沒有辦法分離發送表單中的內容和什麼是被顯示在使用FormControl?
我只能找到一種方法來顯示和設置相同的變量或者只ID或唯一的名字。
<input
formControlName="category"
[formControl]="userForm.controls['category']"
[typeahead]="categoriesObservable"
(typeaheadLoading)="toggleLoadingCategories($event)"
(typeaheadNoResults)="toggleNoCategoriesFound($event)"
(typeaheadOnBlur)="categoryFieldSelected($event)"
(typeaheadOnSelect)="categoryFieldSelected($event)"
typeaheadOptionsLimit="7"
typeaheadOptionField="name"
placeholder="Choose a category"
class="form-control"/>
我會盡快嘗試一下,謝謝! – MattJ