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}}
``

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay