在*ngIf的帮助下,我正试图在单击关闭按钮时关闭引导程序警告框。
在onClick (close)中,我调用了isError=false。我可以将容器值记录为false,但是ng- isError不会消失吗?以下是我的代码
<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);
}发布于 2019-12-19 00:34:01
我试着解决你的问题,但没有得到任何问题。这只是一个非常简单的例子:
https://stackblitz.com/edit/angular-r29kyu
据我所知,您还想隐藏带有alert alert-warning alert-dismissible类的div。如果是这样,那么您也必须将其放入ng-container中。
https://stackoverflow.com/questions/59396198
复制相似问题