My task involves displaying user data from an array and then showing the details of the selected user. I attempted to achieve this with the following code:
users = USERS; // contains data
selectedUser: User;
constructor() { }
ngOnInit() {
}
onSelect(index): void {
this.selectedUser = index;
}
Here is a snippet from my HTML file that I used:
<div class="row">
<div class="col-4">
<ul class="menu">
<div *ngFor="let user of users; let i = index"
(click)="onSelect(i)">
<span><b>{{user.id}}</b></span> {{user.name}}
</div>
</ul>
</div>
<div *ngIf="selectedUser" class="col-8 menu">
<div><span><b>id: </b></span> {{selectedUser.id}} </div>
<div><span><b>Name:</b></span> {{selectedUser.name}} </div>
<div><span><b>Location:</b></span> {{selectedUser.location}} </div>
</div>
</div>
I need help figuring out the correct condition to use in the ngIf directive for displaying the data.