首页 > 解决方案 > html 中的 onChange 转换为 Angular 是什么样的?

问题描述

我有一个“跨度”,当“h2”值等于空时会显示,当“h2”值不为空时会消失。我尝试实现 OnChanges,以便它们相互跟踪值。

我的ts

remindNotify(){
    var x = document.getElementById("notifyTitle");
    var y = document.getElementById("badge");
    if(x == null){
      y.style.display= "block";
    }else{
      y.style.display= "none";
    }
  }

  ngOnChanges(changes: SimpleChanges): void{
    this.remindNotify();
  }

我的html

<span id="badge">#</span>
<h2 id="notifyTitle" >{{ (message | async)?.notification.title }}</h2>

标签: angular

解决方案


推荐阅读