【发布时间】:2021-07-29 07:56:53
【问题描述】:
所以我用补丁值加载我的表单,由于某种原因,mat-select 没有根据值进行选择。
这是我所拥有的:
constructor(private _formBuilder: FormBuilder,
private productServices : ProductsService,
private activatedRoute: ActivatedRoute,
private router : Router) {
this.moods=[
{mood: 'steak-0', viewValue: 'Steak'},
{mood: 'pizza-1', viewValue: 'Pizza'},
{mood: 'tacos-2', viewValue: 'Tacos'}
];
}
ngOnInit() {
this.completeProfileForm = this._formBuilder.group({
title :['',Validators.required],
releaseDate: ['', Validators.required],
resolution: ['', Validators.required],
displayName: ['', Validators.required],
description: ['', Validators.required],
type: ['', Validators.required],
primary_mood: ['', Validators.required],
secondary_mood: ['', Validators.required],
price: [null, Validators.required],
});
}
<mat-form-field class="form-field" appearance="fill">
<mat-label>Primary Mood</mat-label>
<mat-select formControlName="primary_mood" >
<mat-option *ngFor="let mood of moods" [value]="mood.value">
{{mood.mood}}
</mat-option>
</mat-select>
<mat-error *ngIf="completeProfileForm.controls.primary_mood.touched && completeProfileForm.controls.primary_mood.invalid">
<span *ngIf="completeProfileForm.controls.primary_mood.errors.required">Please select your artwork Type.</span>
</mat-error>
</mat-form-field>
i tried to select any of the options the options not selected
你们能帮帮我吗
【问题讨论】:
-
数据类型是
{mood: 'steak-0', viewValue: 'Steak'},但您在 HTML 中使用了[value]="mood.value"而不是mood.viewValue。是不是笔误?
标签: html node.js angular typescript angular-material