首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么*ngIf不能在Angular中使用ng-container

为什么*ngIf不能在Angular中使用ng-container
EN

Stack Overflow用户
提问于 2019-12-19 00:21:44
回答 1查看 2.7K关注 0票数 1

在*ngIf的帮助下,我正试图在单击关闭按钮时关闭引导程序警告框。

在onClick (close)中,我调用了isError=false。我可以将容器值记录为false,但是ng- isError不会消失吗?以下是我的代码

代码语言:javascript
复制
<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">&times;</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文件

代码语言:javascript
复制
 closeError(): void {

this.isError = false;
console.log("Message: ", this.isError);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-19 00:34:01

我试着解决你的问题,但没有得到任何问题。这只是一个非常简单的例子:

https://stackblitz.com/edit/angular-r29kyu

据我所知,您还想隐藏带有alert alert-warning alert-dismissible类的div。如果是这样,那么您也必须将其放入ng-container中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59396198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档