I have the following html file.
JavaScript
x
8
1
<p-selectButton
2
[options]="metrics"
3
[(ngModel)]="selectedMetric"
4
(onChange)="onChange($event)"
5
></p-selectButton>
6
<p>Selected Metric: {{selectedMetric}}</p>
7
<div *ngIf="selectedMetric"==="Metric 1">Selected first </div>
8
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