如何在Angular中显示/隐藏按钮

萨钦·穆图马拉(Sachin Muthumala)

当按钮状态为“批准”并且“批准”按钮为“待定”状态时,我想显示“拒绝”按钮。我正确传递了值,但两个按钮始终显示。

这是我的.ts文件

    export class NotificationComponent implements OnInit {

      notices: notification[] = [];
      public approve_show: boolean = false;
      public disapprove_show: boolean = false;

      constructor(
        private http: HttpClient,
        private router: Router,
      ) { }

      ngOnInit() {

    var url = "http://localhost:3000/notification/view";

    this.http.get<any>(url).subscribe(res => {
      this.notices = res;
      var i = 0;

      for (var prop in res) {
        if (res.hasOwnProperty(prop)) {
          // console.log(res[i].state)          
          if (res[i].state == 'Approved') {
            console.log("approved")
            this.disapprove_show = true
          }
          else {
            this.approve_show = true
          }
          i++;
        }
      }

    }, (err) => {
      console.log(err);
    });
  }
}

这是我的html代码

<button *ngIf="approve_show" mat-raised-button class="approve_btn">Approve</button>
<button *ngIf="disapprove_show"  mat-raised-button color="warn" style="width:100px;">Disapprove</button>
依卡纳雅克

由于您将其用于列表,因此请使用以下内容。 <button *ngIf="res.state=='Approved'" mat-raised-button color="warn" style="width:100px;">

问题是您对按钮使用了全局变量。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在单击按钮时显示隐藏的div并在Angular 2中隐藏单击的按钮?

如何在angular2中单击按钮显示/隐藏组件?

如何在angularjs中单击隐藏和显示按钮?

如何在Android中单击按钮隐藏和显示密码?

如何在 React JS 中隐藏/显示提交按钮

如何在angular.dart中显示或隐藏表格行

单击按钮后,在Angular中隐藏按钮并显示数据

如何在JScrollBar中隐藏箭头按钮

如何在溢出中隐藏按钮?

如何在桌面撰写中隐藏按钮

如何在Xcode 6中隐藏按钮?

如何在UINavigationController中隐藏“后退”按钮?

如何在html中隐藏按钮?

如何在Flutter中显示带有提交按钮和隐藏输入字段的HTML表单

单击按钮时如何在javascript中隐藏/显示下拉菜单

如何在AppleScript应用程序中按下按钮时隐藏标签并显示它?

如何在链接按钮上的gridview中显示和隐藏文本框

如何在 Listview ASP.NET 中添加显示/隐藏密码按钮?

选中单选按钮时如何在html中隐藏和显示输入?

如何显示和隐藏由Angular 2中的动态按钮触发的动态div

如何在JFrame中显示/隐藏JPanel?

如何在TextFormField中显示/隐藏密码?

如何在流星中隐藏/显示元素?

如何在vim中显示隐藏字符?

如何在React中显示/隐藏div?

如何在表单中显示/隐藏模型?

如何在ClojureScript中隐藏/显示表格

如何在YouTubePlayer中显示/隐藏字幕

如何在按钮单击时应用显示和隐藏?