Reputation: 685
I have form like:
<form #testForm="ngForm" (submit)="create(testForm)">
<input type="text" [value]="111" ng-control="test">
<input type="submit" >
</form>
but when I console.log
testForm
in there is no test
key (and testForm.value
is undefined)
Upvotes: 1
Views: 133
Reputation: 2280
Two thing, (submit)
should be (ngSubmit)
and ng-control
should be ngControl
. Also using [value]
to set an initial value wont work, use [(ngModel)]
with an initial value instead.
Here's an example: http://plnkr.co/edit/qi08ZTgFWH2WpHWre7qu
Upvotes: 4
Reputation: 39278
Try this:
<form (ngSubmit)="create()" [ngFormModel]="form" #testForm="ngForm">
<input type="text" ngControl="test">
</form>
the form
instance in my sample is defined in the component code.
Here is a working form demo/article if you need it as well:
http://www.syntaxsuccess.com/angular-2-samples/#/demo/form
http://www.syntaxsuccess.com/viewarticle/forms-and-validation-in-angular-2.0
Upvotes: 4