我有角度分量:
import { Component, OnInit, Inject } from '@angular/core';
import {FormBuilder, FormGroup,Validators,FormArray,FormControl,} from '@angular/forms';
@Component({
selector: 'app-collaborator-detail',
template: `
<h1> This is form</h1>
<form [formGroup]="collaboratorForm">
<div>
<input type="text" placeholder="Email address" formControlName="emailAddress">
</div>
</form>`,
})
export class CollaboratorDetailComponent implements OnInit {
constructor(@Inject(FormBuilder) private fb: FormBuilder) {}
collaboratorForm: FormGroup;
ngOnInit() {
this.initCollaboratorForm();
}
initCollaboratorForm() {
this.collaboratorForm = this.fb.group({
emailAddress: [
{ value: 'some.email@gmail.com', disable: true },
[Validators.email, Validators.required],
]
});
}
}
我希望该值:“ some-email@gmail.com”将作为输入值可见。但是代替它的是,可见值是:“ [object Object]”。
我在这里做错了什么?
答案 0 :(得分:1)
AbstractControl API(所有表单控件的基类)中没有名为disable
的属性,它应该是disabled
。
{ value: 'some.email@gmail.com', disabled: true }