Angular 2 New Forms - Custom Input Validation -


i've converted forms using new forms 0.2.0.

of course, custom validators stopped working...any directions or examples on how write custom input validators in new library?

actually had simple problem: 1) didn't point ng_validators @angular/forms - pointing old forms 2) less importantly, wasn't using abstractcontrol, old control , while didn't cause js problems caused typescript transpile errors.

 /**  * created franz on 5/8/2016.  */ import {directive,provide} '@angular/core'; import {ng_validators} '@angular/forms'; import {password_regex} '../../common/util/rejex'; import {validator, abstractcontrol} "@angular/forms";  function validatepassword(control: abstractcontrol) {   return password_regex.test(control.value) ? null : {     validatepassword: {valid: false}   }; }  @directive({   selector: '[validatepassword]',   providers: [     provide(ng_validators, {       usevalue: validatepassword, // alternative useexisting: passwordvalidator, creates , destroys objects every time.       multi: true     })   ] }) export class passwordvalidator implements validator {   constructor() {}    validate(c: abstractcontrol) {     return password_regex.test(c.value) ? null : {valid: false}   }; } 

Comments