我试图以 angular2 的形式打印输入字段的内容,但在控制台上获取对象作为结果(我的 ControlGroup 类型),这是我的代码,为什么会发生这种情况
import { FORM_DIRECTIVES, ControlGroup, AbstractControl,
FormBuilder, Validators} from 'angular2/common';
@Component({
selector : 'formbuilder',
template : `
<h1> FOrm Using Formbuilder </h1>
<form [ngFormModel] = "myform" (ngSubmit) = "onSubmit(myform.value)">
<lable>Name: </lable>
<input type = "text" [ngFormControl] = "myform.controls['input1']" />
<input type = "text" [ngFormControl] = "myform.controls['input2']" />
<button type = "text">Submit</button>
</form>
`,
directives : [FORM_DIRECTIVES]
})
export class formbuilder {
myform : ControlGroup ;
ac : AbstractControl;
constructor(fb : FormBuilder) {
this.myform = fb.group({
'input1' : ['ABC', Validators.required],
'input2' : ['DEF', Validators.required]
});
this.ac = this.myform.controls['ac']
}
onSubmit(value : any) : void {
console.log("submit method called " + value);
}
}
bootstrap(formbuilder);