如何更新 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;
}
我猜你想做的是:
如果_this.noteValue
是true
:
设置
notificationDetails = {
notification : false
}
- 将
_this.noteValue
设置为 false
。
如果_this.noteValue
是false
:
设置
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
.
我有 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
tofalse
andfalse
totrue
我想你想做如下:
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;
}
我猜你想做的是:
如果
_this.noteValue
是true
:设置
notificationDetails = { notification : false }
- 将
_this.noteValue
设置为false
。
如果
_this.noteValue
是false
:设置
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
.