abid Hussain
abid Hussain

Reputation: 43

can't binding 'ngModel' also not rendering mat-select in angular material angular 6

I am using Angular Material in application and Mat-select are showing Multiple times based upon loop and some conditions i need to select data by default in mat-select in ngAfterViewInit()

Loop which cteate multiple mat-select

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

i am creating multiple mat-select Code

<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 is

 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);
              }
            }

if i display value in itemid the Itemid is correct in ngModel but not rendering the Mat-select Please help

Upvotes: 1

Views: 1162

Answers (1)

Pierre-Henri Sudre
Pierre-Henri Sudre

Reputation: 721

Maybe Angular error: "Can't bind to 'ngModel' since it isn't a known property of 'input'" ?

import { FormsModule } from '@angular/forms';

@NgModule({
    imports: [
         FormsModule      
    ]

Upvotes: 2

Related Questions