Reputation: 85
I am trying to check the filename variable if has value but if the value is null is trying to execute the ngfor
<h2>{{news.content}}</h2>
<ng-container *ngIf="filename">
<div *ngFor="let file of filename">
<img src="{{'http://127.0.0.1:8000/images/'+file}}" style = "width: auto;margin: auto;display: block;">
</div>
</ng-container>
Upvotes: 1
Views: 204
Reputation: 714
To cast any value to boolean and make a secure check, please use double negation operator, like this:
*ngIf="!!filename"
This way,
if true -> false -> true
if 25 -> false -> true
if "Hello world" -> false -> true
if null -> true -> false
if undefined -> true -> false
if false -> true -> false
Upvotes: 0