Template form limitations

While template forms are very simple indeed, and follow a syntax similar to Aurelia forms, it soon becomes difficult to provide advanced functionality on a form using template syntax. As an example, consider the following form control:

<input type="text" [(ngModel)]="Name" required minlength="4"> 

Here, we have an input element that is bound to the component property called Name. Note that we have two extra attributes, which are actually field validators. One is required, which specifies that this input cannot be left blank. The other is minlength, which is set to a value of 4. So using template syntax, this input field will be validated before the form itself becomes valid. It is both required, and has a minimum length of 4.

Unfortunately, when building larger forms, these validators could quite easily change depending on the context of the form, or depending on other input that the user has selected. Because of these limitations in using template syntax, Angular has introduced the concept of Reactive forms.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.110.119