【发布时间】:2018-08-24 06:40:21
【问题描述】:
我是 Angular 4 的新手。我正在尝试使用 Web 服务删除在 DB 中创建的组。如果该组拥有任何用户,那么我必须向用户发出警告消息。如果组是空的,我可以删除它。 对于警告消息,我使用了引导模式并删除了具有 Angular 功能(deleteGroup(group)),它将依次调用 Web 服务来删除组。
根据该组中的用户数,我尝试使用 *ngIf,但失败了。谁能帮我解决一下?
功能流程:
1) Groups are listed in drop-down and the user chooses the one
2)Clicking on delete button, calls the getUsers() funtion to check
the availability of users in that group (group members count is
assidgned to usersCount variable )
3) Based on the usersCount, next step has to be done
a) usersCount == 0 , => delete the group
b) usersCount !=0 , => pop-up warning message
HTML 代码
<button type="button" class="btn btn-primary"
(click)="getUsers(optionSelected)" >Delete</button> //getuser function gets the number of users in that group
<div *ngIf="usersCount ==0 ">deleteGroup(optionSelected)</div> //usercount -> number of users
</button>
打字稿代码:
getUsers(value): void {
this.output = [];
this.textValue.getUsers(value)
.subscribe(res => {
this.output = res;
this.usersCount = this.output.length;
console.log ("Number of users:", this.usersCount);
})
}
【问题讨论】:
-
也添加打字稿代码。 usercount 在控制台中打印什么?
-
添加了打字稿代码供您参考。 Userscount 变量保存该组中的用户数。
标签: angular function angular-ng-if