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:
We can use multiple conditions in *ngIf with logical operator AND (&&) to decide the trustworthy of *ngIf expression. If all conditions are true, then element will be added to the DOM.
The asterisk is "syntactic sugar". It simplifies ngIf and ngFor for both the writer and the reader. Under the hood, Angular replaces the asterisk version with a more verbose form.
Use double equal to == operator to check equality or better use === to check strict equality. Save this answer.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With