If statement 如何更新if条件中的值

If statement 如何更新if条件中的值,if-statement,angular,typescript,ionic2,If Statement,Angular,Typescript,Ionic2,我遇到的情况是checknotificationObj=“true”(即\u this.noteValue=“true”)如下所示 现在,当它在.ts中输入if条件时,如何使该\u this.noteValue=false。这同样适用于其他部分 我是新来的安格拉请帮帮我 let checkNotifictionObj = _this.noteValue; if(checkNotifictionObj){ notificationDetails={ n

我遇到的情况是
checknotificationObj=“true”
(即
\u this.noteValue=“true”
)如下所示

现在,当它在.ts中输入if条件时,如何使该
\u this.noteValue=false
。这同样适用于其他部分

我是新来的安格拉请帮帮我

let checkNotifictionObj = _this.noteValue;
     if(checkNotifictionObj){
        notificationDetails={
          notification:"flase"
        };
       _this.noteValue="false";
     }
     else{
       notificationDetails={
         notification:"true"
       };
       _this.noteValue="true";
     }
我无法将CheckNotificationObj
true
更新为
false
false
更新为
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;
}

我认为您希望按以下方式进行:

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;
}

我想你想做的是:

  • 如果
    \u此.note值

    • 设置

      notificationDetails = {
        notification : false
      }
      
      notificationDetails = {
        notification : true
      }
      
    • 将此.noteValue设置为
      false
  • 如果
    \u此.noteValue
    false

    • 设置

      notificationDetails = {
        notification : false
      }
      
      notificationDetails = {
        notification : true
      }
      
    • 将此.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

    我想您要做的是:

  • 如果
    \u此.note值

    • 设置

      notificationDetails = {
        notification : false
      }
      
      notificationDetails = {
        notification : true
      }
      
    • 将此.noteValue设置为
      false
  • 如果
    \u此.noteValue
    false

    • 设置

      notificationDetails = {
        notification : false
      }
      
      notificationDetails = {
        notification : true
      }
      
    • 将此.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