I was struggling with adding template driven form validation
in my angular2 app.
i have a forked the plunker https://plnkr.co/edit/phhe74kAUmNZgNSmcsvm?p=pr
Currently, your form doesn't recognize your child components' input field as a form field, you need to change your child tag a bit... to have the name
attribute and ngModel
to bind this child component to the form. Also include required
here.
Lastly, you need to add ngDefaultControl
to have two-way binding for the form field. So your child tag should look like this in your parent:
<my-input name="postcode" ngModel ngDefaultControl required [(value)]="user.address.postcode"></my-input>
Here is your forked