I'm trying to display one of two options with string interpolation in my html file based on the condition in my typescript file, if the variable cityName = '' is an empty string then interpolate
{{currentLocationCity.name}} and if the variable cityName = '!null'
is not an empty string then interpolate {{cityByCoordiantes.name}}
, how can i achieve this, i can write two different divs for each result and use *ngIf to display one of them, but i think that there has to be a better way of achieving this.
-
1Did you try using Conditional Operator inside your template?thisdotutkarsh– thisdotutkarsh2021-09-09 12:23:04 +00:00Commented Sep 9, 2021 at 12:23
-
1Instead of nesting div's for conditionally rendering, you can use <ng-container *ngIf=""></ng-container>Fatih Ersoy– Fatih Ersoy2021-09-09 12:23:47 +00:00Commented Sep 9, 2021 at 12:23
Add a comment
|