Skip to content
Advertisement

How to use ngIf condition with a constant and a ngModel

I have the following html file.

JavaScript

The above is obviously incorrect. What is the correct syntax for my ngIf directive if I want to compare {{selectedMetric}} and a string constant like “option 1”?

Advertisement

Answer

<div *ngIf="selectedMetric==='Metric 1'">Selected first </div> should to the trick to compare a variable against a literal string

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement