Issue
I am working with some JSON and want to display the menu in angular only if the image is not null, example JSON is as follows, so if image is null don't show the component, any idea how to loop through this JSON in HTML, I am working on Angular.
Json:
users = [
{
user: [
image: 'user1.png',
data: {
name: 'abc'
}
]
}
{
user: [
image: null,
data: {
name: 'xyz'
}
]
},
{
user: [
image: 'user1.png',
data: {
name: 'xyzz'
}
]
}
]
Html
<div *ngFor="let user of users">
// want to show this component only if there is image
// want to do something like that
// ngIF="user.image != null" then show but its not working
<user-image [user]="user"></user-image>
</div>
Solution
Change it to.
<div *ngFor="let user of users">
<user-image *ngIf="user?.image" [user]="user"></user-image>
</div>
Answered By - Prashant Singh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.