Ali
Ali

Reputation: 1759

ngIf One-line if statements | Angular 6

i want to change the name displayed on the iteration using ngIf, i am trying to do something like this:

*ngIf="detail.name=='dieselG_d'? detail.name='Diesel Green':Diesel Red

and the console recorded the following error:

Uncaught Error: Template parse errors:

Upvotes: 5

Views: 12591

Answers (1)

Amethystx87
Amethystx87

Reputation: 488

I think you're using the wrong directive here- *ngIf is moreso to check if we should display the content at all, not to make an assignment and change a a variable. It requires a statement that evaluates a true or false, and cannot do assignments.

Something like the following might work better for you, if your goal is to display a certain name, rather than to hide content with certain values.

<div> {{ detail.name === 'dieselG_d' ? 'Diesel Green' : 'Diesel Red' }} </div>

Upvotes: 9

Related Questions