![](/img/trans.png)
[英]How to bind C# dictionary to the dropdown list in angular 6 material
[英]How to bind data on angular material dropdown in angular 5?
基本上我正在更新具有用戶信息的用戶資料。 分別綁定到用戶各自的字段上。
this.editOfferprice= new FormGroup({
xyz : new FormControl(xxxx,[]),
xxx: new FormControl(xxxx,[Validators.required]),
wwwID : new FormControl(xxxx,[Validators.required]))};
在上面的代碼上,我使用了formgroup和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>
我想知道如何在下拉列表上綁定數據?
使用[ngValue]
*ngFor="let P of Pro" [ngValue]="P.ID">
在這樣的選擇中嘗試使用ngModel
進行綁定-
<mat-form-field>
<select matNativeControl [(ngModel)]="selectedOption" required>
<option *ngFor="let P of Pro [value]="P.ID">{{P.Name}}</option>
</select>
</mat-form-field>
或者,如果您想使用formControl,請按以下步驟進行操作-
[formControl]="yourControl"
由於Angular中的此問題 ,請綁定formControl實例,而不要使用formControlName 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.