3

How to set expression value to typescript local variable in HTML template I am trying to assign expression value to the variable like this:

<span *ngIf="IsRangeValidate = !(section.FOFormFieldList[fieldIndex].FOFormFieldResponseText>=fieldInfo.MinVal && section.FOFormFieldList[fieldIndex].FOFormFieldResponseText<=fieldInfo.MaxVal)" class="text-danger">Value should be between {{fieldInfo.MinVal}} - {{fieldInfo.MaxVal}}</span>

The expression will return true/false value. IsRangeValidate is TypeScript boolean variable and I want to assign expression result to this variable from HTML template

Parth Savadiya
  • 1,203
  • 3
  • 18
  • 40
  • May be this answer can help you. https://stackoverflow.com/questions/38582293/how-to-declare-a-variable-in-a-template-in-angular2 – Karan Patel Dec 15 '17 at 12:09

1 Answers1

0

If you want to store actually value in IsRangeValidate. You can create a getter in your component and use it.

 get isRangeValidate() {
   const text = this.section.FOFormFieldList[fieldIndex].FOFormFieldResponseText;
   return text >= this.fieldInfo.MinVal && text <= this.fieldInfo.MaxVal)
 }

And use this getter in your template:

 <span *ngIf="isRangeValidate" class="text-danger">Value should be between {{fieldInfo.MinVal}} - {{fieldInfo.MaxVal}}</span>

I hope this answer is helpful for you.

  • Thanks, @Natalya I know this but actually, I don't want to write code in typescript I just want to do same from HTML template. – Parth Savadiya Dec 15 '17 at 13:40