[英]why *ngIf not working with ng-container in Angular
我正在尝试在 *ngIf 的帮助下单击关闭按钮关闭引导程序警报框。
在 onClick(关闭)中调用 isError=false。 我可以将 isError 值记录为 false 但 ng-container 没有消失? 这是我的代码
<div class="error-list">
<ng-container *ngIf="isError">
<ngb-alert type="danger" (click)="closeError()">{{errorMessage}}</ngb-alert>
</ng-container>
<div class="alert alert-warning alert-dismissible" role="alert">
<span type="button" class="close" data-dismiss="alert" aria-label="Close"><span
aria-hidden="true">×</span></span>
<strong>Warning!</strong> {{errorMessage}}.
</div>
</div>
.error-list {
position: fixed;
bottom: 0;
width: 100%;
z-index: 100;
}
::ng-deep .alert {
margin-bottom: 0;
}
.ts 文件
closeError(): void {
this.isError = false;
console.log("Message: ", this.isError);
}
我尝试解决您的问题,但没有任何问题。 这只是一个非常简单的例子:
https://stackblitz.com/edit/angular-r29kyu
根据我的理解,您还想使用类alert alert-warning alert-dismissible
隐藏 div。 如果是这样,那么您也必须将其放入ng-container
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.