I want to display the user list only when the check is true, and show that data is not available if the check is false.
Here I am adding my ts file and html file
import { Component, OnInit } from '@angular/core';
import { UserDataService } from '../services/user-data.service';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.css']
})
export class UsersComponent implements OnInit {
check: any = false;
pageTitle = 'Users List';
errorMessage = '';
//users: IUser[]=[];
users: any;
constructor(private userService: UserDataService) { }
ngOnInit(): void {
this.userService.users().subscribe({
next: (users: any) => {
this.users = users;
this.check = true;
console.log("this.users");
console.log(this.users);
},
error: (err: any) => this.errorMessage = err
})
}
}
<p>users works!</p>
<div>*********************User Component*******************</div>
<p>{{check}}</p>
<div *ngIf="check">Data not available</div>
<ul *ngIf="check">
<li *ngFor="let user of users">
{{user.name}}
</li>
</ul>