如何更新 if 条件内的值

how to update a value inside the if condition

我有 checknotificationObj="true" (即 _this.noteValue="ture" )的情况,如下所示。

现在如何在它进入 .ts 中的 if 条件时实现 _this.noteValue =false。同样的 visiversa 用于其他部分

我是angular2的新手,请帮助我

let checkNotifictionObj = _this.noteValue;
     if(checkNotifictionObj){
        notificationDetails={
          notification:"flase"
        };
       _this.noteValue="false";
     }
     else{
       notificationDetails={
         notification:"true"
       };
       _this.noteValue="true";
     }

i am not able to update checkNotifictionObj true to false and false to true

我想你想做如下:

let checkNotifictionObj:boolean = _this.noteValue; // _this.noteValue must be of boolean type
if(checkNotifictionObj){
  notificationDetails={
    notification : false
  };
  _this.noteValue = false;
} else {
  notificationDetails={
    notification : true
  };
  _this.noteValue = true;
}

我猜你想做的是:

  1. 如果_this.noteValuetrue:

    • 设置

      notificationDetails = {
        notification : false
      }
      
    • _this.noteValue 设置为 false
  2. 如果_this.noteValuefalse:

    • 设置

      notificationDetails = {
        notification : true
      }
      
    • _this.noteValue 设置为 true

更简单的方法是:

_this.noteValue = !_this.noteValue; // If _this.noteValue is equal to true, now it will be set to false. If it's false, it will be set to true.

notificationDetails = {
  notification: _this.noteValue
};

这样你就不需要 if/else.