无法绑定 'ngModel' 也无法在 angular material angular 中呈现 mat-select 6
can't binding 'ngModel' also not rendering mat-select in angular material angular 6
我在应用程序中使用 Angular Material 并且 Mat-select 根据循环和某些条件显示多次
我需要在 ngAfterViewInit()
中的 mat-select 默认情况下 select 数据
形成多个垫子的循环-select
*ngFor="let p of GlobalVariableService.controllsApplicationTypeFields;let filedIndex = index "
我正在创建多个垫子-select 代码
<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
请帮助
也许 ?
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
]
我在应用程序中使用 Angular Material 并且 Mat-select 根据循环和某些条件显示多次 我需要在 ngAfterViewInit()
中的 mat-select 默认情况下 select 数据形成多个垫子的循环-select
*ngFor="let p of GlobalVariableService.controllsApplicationTypeFields;let filedIndex = index "
我正在创建多个垫子-select 代码
<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 请帮助
也许
import { FormsModule } from '@angular/forms';
@NgModule({
imports: [
FormsModule
]