簡體   English   中英

為什么在 angular6 的 ng-multiselect-dropdown 中未定義 idField?

[英]Why idField is undefined in ng-multiselect-dropdown in angular6?

我有ng-multiselect-dropdown angular 應用程序。 為了提供dropdown列表,我從ngOnInit內部的api獲取services ,就像這樣

selectedOfferedServices: IDropdownSettings = {};

ngOnInit(){
   this.getServices();
   this.selectedOfferedServices = {
     singleSelection: false,
     idField: 'id',
     textField: 'deliveryTypeName',
     selectAllText: 'Select All',
     unSelectAllText: 'UnSelect All',
     itemsShowLimit: 2,
     allowSearchFilter: false
   };
} 

在我的template我有一個條件*ngIf並且在*ngIf表達式中獲得 true 后,將*ngIfng-multiselect-dropdown *ngIf ng-multiselect-dropdown 當用戶從我的模板中的普通select dropdwon 中選擇任何選項時,此表達式變為真,然后顯示此ng-multi-select-dropdown

<div class="row" *ngIf="transporterOtherDetails === 'yes'">
    <div class="col-3">
      <div class="form-group">
          <label>Offered Services</label>
          <ng-multiselect-dropdown [placeholder]="'Select services'" [data]="deliverytypes"
          [(ngModel)]="selectedServices" [ngModelOptions]="{standalone: true}"
          [settings]="dropdownSettings">
        </ng-multiselect-dropdown>
      </div>
    </div>
</div>

但這里的問題是,當我從模板中的正常dropdown中選擇選項時,這個ng-multi-select-dropdown顯示但在控制台錯誤是這樣的

ERROR TypeError: Cannot read property 'idField' of undefined at ng-multiselect-dropdown.js:189

任何人都可以讓我知道這有什么問題嗎?

我得到了解決方案。 我解決了這個問題,只是在data參數之前移動我的settings參數。 這對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM