Unable to use template variables inside ts file

#1

we are using <ion-tags-input [(ngModel)]=“tags” [verifyMethod]=“verifyTag”> as follows
<ion-tags-input [(ngModel)]=“emails” [type]="‘email’" [color]="’#DC7054’" [maxTags]=“10” [once]="‘true’" (onChange)=“onChange()” [verifyMethod]=“verifyTag”>myname@gmail.com;
but inside the functiion verifyTag we are unable to use ‘this reference’ or any other ts variable

verifyTag(str: string): boolean{
console.log(" gottttttttttttttttttttttt" + JSON.stringify(str) + “other” + this.email.toLocaleLowerCase())
// if(email== str){
// return false;
// }

var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(str).toLowerCase());

}

can anyone suggest how to fix this?

#2

Hello,

best way to fix is to use preformatted text, so that other people can read, what you are writing.

It seems maybe that you use in html verifyTag, that not exist on .ts side. On ts side exist something totally different verifyTag(str: string).
Simplier and imho better is you use a variable in ts, that you change as you want

let isverifyed = false;

and in html

<ion-tags-input  [verifyMethod]=“isverifyed”>

Best regards, anna-liebt

#3

Read this if you are interested in the details of the issue, but if you’re not, simply follow these rules:

  • never type the word function inside the body of one
  • never pass object methods as bareword arguments to anything outside your code

[verifyMethod]=“verifyTag” breaks rule #2. Instead, you can try making a closure:

verifyEmail: (email: string) => boolean;
constructor() {
  this.verifyEmail = (email) => {
    return email === this.email.toLocaleLowerCase();
  };
}
[verifyMethod]="verifyEmail"