Reputation: 6358
I have the following html file.
<p-selectButton
[options]="metrics"
[(ngModel)]="selectedMetric"
(onChange)="onChange($event)"
></p-selectButton>
<p>Selected Metric: {{selectedMetric}}</p>
<div *ngIf="selectedMetric"==="Metric 1">Selected first </div>
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"?
Upvotes: 0
Views: 1104
Reputation: 103
Another alternative, to use a defined constant within your .ts file of the component, and initialize it's that variable's value in the constructor.
Upvotes: 0
Reputation: 28434
<div *ngIf="selectedMetric==='Metric 1'">Selected first </div>
should to the trick to compare a variable against a literal string
Upvotes: 2