0

I need to use ngIf and ngFor on the

<option *ngFor="let price of product['pricingDetails']" *ngIf="price['chainPrice']" >

but it shows me Can't have multiple template bindings on one element. Use only one attribute prefixed with * error. What is the best way to use both in the element?

e.k
  • 1,333
  • 1
  • 17
  • 36
  • Possible duplicate of [Using ngIf and ngFor in option](https://stackoverflow.com/questions/39570915/using-ngif-and-ngfor-in-option) – Sasuke Uchiha Sep 05 '19 at 07:30
  • Possible duplicate of [\*ngIf and \*ngFor on same element causing error](https://stackoverflow.com/questions/34657821/ngif-and-ngfor-on-same-element-causing-error) – Azzam Asghar Sep 05 '19 at 07:33
  • Sasuke Uchiha thank you. – e.k Sep 05 '19 at 07:43

2 Answers2

0

try using this ,

<select>

<ng-container *ngFor="let price of product['pricingDetails']">
<option  *ngIf="price['chainPrice']" >
   {{ display anythjing }}
</option>

</ng-container>
</select>


Try my updated code .

Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43
  • 1
    What I'm asking is I need *ngIf for the options only. The above method will produce empty options element – e.k Sep 05 '19 at 07:41
  • This will still create an option. That just won't have anything in it but still the option will be created. That not required i guess. – Azzam Asghar Sep 05 '19 at 07:41
0

Use this:

[hidden]="!price['chainPrice']"

instead of this:

*ngIf="price['chainPrice']"
tom
  • 9,550
  • 6
  • 30
  • 49