显示隐藏成功失败警报

时间:2018-06-22 01:52:22

标签: angular

我正在使用Angular 5。我要做的是根据如下所示执行的代码块显示成功/失败Alert

showerror是布尔值。

 ...
.subscribe(data =>{
        this.showerror = false
    },
      error =>{
        this.showerror = true
      }
    );

我的HTML看起来像这样:根据上面的TS代码输出的结果,我只想显示以下成功/失败代码块之一。有人可以在这里帮我吗。

<div class="alert alert-success" role="alert" [hidden]="{{showerror}}">
  success !! you did it
</div>
<div class="alert alert-danger" role="alert" [hidden]="{{showerror}}">
  Fail!!!
</div>

3 个答案:

答案 0 :(得分:0)

删除注释 {{}}

<div class="alert alert-success" role="alert" [hidden]="showerror">

答案 1 :(得分:0)

您可以尝试像这样自定义$mdDialog:-

 ...
.subscribe(data =>{
        alert = $mdDialog.alert()
                  .title('success !! you did it')
                  .ok('Close');
                  $mdDialog.show(alert).finally(function() {
                      alert = undefined;
                    });;
    },
      error =>{
        alert = $mdDialog.alert()
                  .title('Fail!!!')
                  .ok('Close');
                  $mdDialog.show(alert).finally(function() {
                      alert = undefined;
                    });;
      }
    );

答案 2 :(得分:0)

 <div class="alert alert-success" role="alert" [hidden]="!showerror">
    success !! you did it
  </div>

<div class="alert alert-danger" role="alert" [hidden]="showerror">
  Fail!!!
</div>