0

basically i am Updating user profile on which i have a user info. which is to be bind on the user respective fields.

    this.editOfferprice= new FormGroup({
        xyz : new FormControl(xxxx,[]),
        xxx: new FormControl(xxxx,[Validators.required]),
        wwwID : new FormControl(xxxx,[Validators.required]))};

on above code am using formgroup and formcontrol.

<mat-form-field fxFlex="49"> <mat-select placeholder="Select xxx" formControlName="xxx"> <mat-option *ngFor="let P of Pro" [value]="P.ID"> {{P.Name}} </mat-option> </mat-select> <mat-error *ngIf="editOffer.controls['xxx'].errors && editOfferprice.controls['xxx'].errors.required"> You must select NAme</mat-error> </mat-form-field>

i want to know how to bind data on dropdown?

1

2 Answers 2

0

use the [ngValue]

*ngFor="let P of Pro" [ngValue]="P.ID">
Sign up to request clarification or add additional context in comments.

1 Comment

should work with value as well, see material.angular.io/components/select/examples
0

Try binding using ngModel in the select like this -

<mat-form-field>
  <select matNativeControl [(ngModel)]="selectedOption" required>
    <option *ngFor="let P of Pro [value]="P.ID">{{P.Name}}</option>
  </select>
</mat-form-field>

or if you want to use formControl do it like this -

[formControl]="yourControl"

Due to this issue in Angular bind the formControl instance instead of using formControlName.

Working Example

Comments