无法绑定"ngModel"也无法在角度材料角度 6 中渲染垫子选择



我在应用程序中使用角度材料,并且根据循环和某些条件显示多次 我需要在 ngAfterViewInit(( 中的 mat-select 中默认选择数据

循环,其中引用多个垫子选择

*ngFor="let p of GlobalVariableService.controllsApplicationTypeFields;let filedIndex = index "

我正在创建多个垫子选择代码

<div class="mt-3 example-full-width"
*ngIf="(p.FK_FieldType == '6') && p.FK_PanelId == k.PanelId">
<div *ngFor="let list of  GlobalVariableService.listSelectData">
<mat-form-field *ngIf="list.id == p.FieldId" class="w-95">
<mat-select matNativeControl name="ApplicationStatusId"
[(ngModel)]="GlobalVariableService.controllsApplicationTypeFields[filedIndex].DefaultValue"
required>
<mat-option *ngFor="let l of list.FieldListItems" [value]="l.ItemId">
{{GlobalVariableService.isEn === true ? l.FieldText : l.FieldTextAr}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>

Ts.code 是

for (var ls = 0; ls < this.GlobalVariableService.controllsApplicationTypeFields.length; ls++) {
if (Control == this.GlobalVariableService.controllsApplicationTypeFields[ls].FieldId) {
this.GlobalVariableService.controllsApplicationTypeFields[ls].DefaultValue = this.GlobalVariableService.ApplicationValues[i].Value;
debugger;
console.log("selected value is");
console.log(this.GlobalVariableService.controllsApplicationTypeFields[ls].DefaultValue);
}
}

如果我在 Itemid 中显示值,则 Itemid 在 ngModel 中是正确的,但不渲染 Mat-select 请帮忙

也许角度错误:"无法绑定到'ngModel',因为它不是'input'的已知属性"?

import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule      
]

最新更新