DEV Community

AlishaAS
AlishaAS

Posted on

I want to display data in an Angular application based on true or false values.

If the check is angular application true, I want to show the user list and if the check is false I want to show that the data is not available, but currently the user list is being displayed for both true and false.
``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

})
}

}

users works!

******************User Component****************

{{check}}

Data not available

  • {{user.name}}
``

Top comments (0)