Reputation: 423
HTML:(Here I have dropdown to get selected value. I used value binding to get value.I have tried ngModel also but its not working. What is wrong in my code? can you help me?)
<mat-form-field>
<mat-select placeholder="Team NO" formControlName="team" [(value)]="teamNO" required>
<mat-option *ngFor="let list of teamList" [value]="list" >{{list}}</mat-option>
</mat-select>
</mat-form-field>
component.ts
teamList = ['1','2','3','4','5','6','7','8','9','10'];
teamNO : any;
ngOnInit(){
this.operatorService.currentEditSchedule.subscribe((result: any) =>{
if(!!result){
console.log(result)
this.teamNO = result.teamNo
}
})
}
Upvotes: 1
Views: 1036
Reputation: 1896
Try to use ngModel instead of value in mat-select:
<mat-form-field>
<mat-select placeholder="Team NO" formControlName="team" [(ngModel)]="teamNO" required>
<mat-option *ngFor="let list of teamList" [value]="list" >{{list}}</mat-option>
</mat-select>
</mat-form-field>
In case you get a number from your backend, it can help to convert it to a string:
this.teamNO = result.teamNo + '';
Upvotes: 1