Hi,

I have a reactive form and inside the class, I have a bunch of custom 
(group)validators. 
>From within the validator function, I need to set a variable that is 
defined in the class, but I get an "undefined is not an object" error. 
Since all the other functions work just fine, I presume it has something to 
do with the AbstractControl.

Here's an example of the code: 

errorVar: boolean = false
function(c: AbstractControl): {[key: string]: string } | null {
 // validation if 'test' is true or not goes here
 if(test) {
  let errorMessageText: "test"
  return {'errorText': errorMessageText};
 }return null;}


This fails:

 errorVar: boolean = false

  function(c: AbstractControl): { [key: string]: string } | null {
    // validation if 'test' is true or not goes here
    if (test) {
      this.errorVar = true;
      let errorMessageText:
        return { 'errorText': errorMessageText };
    }

    this.errorVar = false;
    return null;
  }


So my idea was to maybe set the variable errorVar during the return, but I 
can't seem to be able to append it to function(c: AbstractControl): { [key: 
string]: string } | null {  

Anybody got some ideas?

Thanks, Phil

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to