为什么 Angular6 的 ng-multiselect-dropdown 中的 idField 未定义?

Fah*_*ari 0 javascript angular

我有角度应用程序,其中有ng-multiselect-dropdown. 为了向我提供列表,dropdown我services从api内部得到ngOnInit这样的信息

selectedOfferedServices: IDropdownSettings = {};

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

在我的内部,template我有一个条件,并且在获得表达*ngIf的真实内部后,就会显示出这一点。当用户从我的模板中的正常 dropdwon 中选择任何选项时,此表达式变为 true,然后显示。*ngIfng-multiselect-dropdownselectng-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>
Run Code Online (Sandbox Code Playgroud)

但这里的问题是,当我dropdown在模板中选择正常选项时,这ng-multi-select-dropdown会显示,但在控制台中错误会像这样出现

ERROR TypeError: Cannot read property 'idField' of undefined at ng-multiselect-dropdown.js:189
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这有什么问题吗?

Fah*_*ari 5

我得到了这个问题的解决方案。我解决了这个问题,只是将我的settings参数移到data参数之前。这对我有用。