【发布时间】:2021-09-19 15:24:13
【问题描述】:
美好的一天。我有一个场景,根据条件显示组件,我正在寻找一种清晰的方式和优化的方式来做到这一点。我在下面有一项服务,它将检查 3 个条件,例如用户是否存在于同一个帐户中、用户存在于其他帐户中并且用户不存在于任何帐户中。
如果用户与其他帐户存在,则显示 div 1 并隐藏 div 2 和 div 3。如果用户不存在于任何帐户上,则显示 div 2 并隐藏 div 1 和 div 3。如果用户存在于同一帐户中,则隐藏所有 div .
只要调用getStarted函数,总是触发div show的显示和隐藏。有什么想法吗?谢谢。
#假设我有 3 个 div
<div class="1">
</div>
<div class="2">
</div>
<div class="3">
</div>
getStarted() {
if (this.userService) {
this.userService.checkUserEmail(this.accountId,email).subscribe(
(res: any) => {
if (res.isSuccess === false) {
console.log("user already exists on this account")
} else if (res.isSuccess === true) {
console.log("user exists on another account")
} else {
console.log("User does not exist on any accounts")
}
},
(err: any) => {
this.notificationService.showError('Something went wrong, Try again later.');
}
);
} else {
this.notificationService.showError('Something went wrong, Try again later.');
}
}
【问题讨论】:
标签: angular typescript angular-material