Angular2 Custom Form Validators losing access to `this` in class Angular2 Custom Form Validators losing access to `this` in class typescript typescript

Angular2 Custom Form Validators losing access to `this` in class


Your validator is not being called with your component as this. Notice that you are passing a loose reference to this.userNameAsyncValidator You can bind your validator without worrying about this conflicts because angular validation doesn't rely on this

userName = new FormControl("", [    Validators.required], [    this.userNameAsyncValidator.bind(this)]);