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";
}
我无法将CheckNotificationObjtrue
更新为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