priyanka nannapaneni priyanka nannapaneni - 2 months ago 9
TypeScript Question

how to update a value inside the if condition

i have situation where

checknotificationObj="true"
(i.e
_this.noteValue="ture"
) as you can see below.

now how to make that
_this.noteValue =false
when it enters the if condtion in .ts . this same visiversa for else part

I am new to angular2 help me please

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


Answer

I think you want to do it as below :

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