Considering the advantages and disadvantages of Driven Driven and Model Driven Forms templates in Angular 2 (beta.0), I wonder how custom validation can be tied to a simple text input field using Driven Forms templates. There are no examples for this approach (other than required) or I have not found them.
<form #f="ngForm"> <label for="name">Name</label> <input type="text" ngControl="name" [(ngModel)]="obj.name" #name="ngForm"> <button type="button" (click)="save()">Save</button> </form>
As an example check function:
validate(control:Control):ValidationResult { if (control.value === 'Monkey') { return { invalidName: true } } }
The above validation function works using FormBiven. How can this be done using the Template Driven approach?
An answer like "This is impossible and will not be in the future." or "It's not best practice, go with the Model Driven approach." along with the argument will be more than beautiful with me. (I already assume that there is no way but to find no evidence on the Internet, and I prefer the Model Driven approach.)
source share