Here is a working example (you need to trust me that the controller has a submit () method - it prints an object, for example {user: 'abc'}, if "abc" is entered in the input field):
<form #loginForm="ngForm" (ngSubmit)="submit(loginForm.value)"> <input type="text" name="user" ngModel required> <button type="submit" [disabled]="loginForm.invalid"> Submit </button> </form>
As you can see:
- don't use loginForm.form, just use loginForm
- loginForm.invalid works just like! loginForm.valid
- If you want submit () to pass the correct values, the input element must have ngModel name and attributes
Also, this is when you are NOT using the new FormBuilder, which I recommend. When using FormBuilder, everything is very different.
user1738579 Jul 07 '17 at 2:16 on 2017-07-07 02:16
source share