Im trying to print content of input field in the form of angular2 but getting object at the console as result (myform type of ControlGroup), here is my code look like, why this happens actually
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);
myform.valuewill give you the value of a text field? You're literally asking for the value of the entire form.