When does Angular2 custom validator directives get called? -


i followed below blog create custom validator directive. http://blog.thoughtram.io/angular/2016/03/14/custom-validators-in-angular-2.html

through chrome debugger see emailvalidator constructor called validate() method never called typed or when field lost focus.

provided code blog below. commented out reference emailblacklist.

<form novalidate>   ...   <input type="email" name="email" ngmodel validateemail> </form>   import {directive, forwardref} '@angular/core'; import {ng_validators, formcontrol} '@angular/forms';  function validateemailfactory(/*emailblacklist: emailblacklist*/) {   return (c: formcontrol) => {     let email_regexp = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;      return email_regexp.test(c.value) ? null : {       validateemail: {         valid: false       }     };   }; }  @directive({   selector: '[validateemail][ngmodel],[validateemail][formcontrol]',   providers: [     { provide: ng_validators, useexisting: forwardref(() => emailvalidator), multi: true }   ] }) export class emailvalidator {    validator: function;    constructor(/*emailblacklist: emailblacklist*/) {     this.validator = validateemailfactory(/*emailblacklist*/);   }    validate(c: formcontrol) {     return this.validator(c);   } } 


Comments