0

I have two directives, one directive accepts a nonnegative number and the other accepts only positive numbers based on some types.

In HTMLtemplate how can do the conditional statement?

  <input *ngIf="productType ==='Amazon' ? OnlyNumber="true" : NegativeNumber" type="text" formControlName="price">

two directives below

OnlyNumber="true" directive for positive NegativeNumber: directive for negative

Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71
  • Does this answer your question? [Apply a directive conditionally](https://stackoverflow.com/questions/44597077/apply-a-directive-conditionally) – ruth Sep 02 '20 at 17:21
  • @that is one directive with some condition but in my case two directives , i have check some property value if true assign one directive else another directive. – Mohamed Sahir Sep 02 '20 at 17:28
  • 2
    You could do add each directive in the corresponding condition: ``. Only either of the element will be rendered since the conditions are contradictory. – ruth Sep 02 '20 at 17:39
  • oh ok let me try this.. is it able to do with single input field `*ngIf="productType==='Amazon'" ? directiveone : directivetwo'"` – Mohamed Sahir Sep 02 '20 at 17:46
  • 1
    It won't be possible. The condition will try to evaluate `directiveone` and `directivetwo` as variable names instead of directive selectors. – ruth Sep 02 '20 at 17:55
  • @thanks for the valuable comments. it works.. – Mohamed Sahir Sep 02 '20 at 18:36

0 Answers0