我正在尝试设置2个字段值<input matInput>abnd <mat-select>编程.对于文本输入,一切都按预期工作,但是对于<mat-select>视图,这个字段就像它有价值一样null.但是,如果我打电话,console.log(productForm.controls['category'].value它会打印出我以编程方式设置的正确值.我错过了什么吗?
这是代码:
表单配置:
productForm = new FormGroup({
name: new FormControl('', [
Validators.required
]),
category: new FormControl('', [
Validators.required
]),
});
Run Code Online (Sandbox Code Playgroud)
设定值:
ngOnInit() {
this.productForm.controls['name'].setValue(this.product.name);
this.productForm.controls['category'].setValue(this.product.category);
}
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<mat-form-field>
<mat-select [formControlName]="'category'"
[errorStateMatcher]="errorStateMatcher">
<mat-option *ngFor="let category of categories" [value]="category">
{{category.name}}
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
angular2-forms angular-material2 angular angular-reactive-forms angular5
我想删除iOS上ListView上的默认行为 - 突出显示项目.我试着设置背景颜色.它没有成功.我在github上发现了这个问题https://github.com/NativeScript/NativeScript/issues/455 但是我不知道如何在Angular nativescript中实现这一点