I am aiming to set class variables to the session storage value if that value exists from the session storage. Otherwise the variable will remain with its default value (which is set in ngOnInit).
private getTableSessionItems = () => {
var tSession = JSON.parse(sessionStorage.getItem('tableSession'));
if(tSession){
for (var property in tSession) {
if (tSession.hasOwnProperty(property)) {
tSession[property]; //Would like to set values equal here this.property = tSession[property]
}
}
console.log('tableSession is true');
}
else{
this.setTableSessionItems();
console.log('nope keep trying', tSession);
}
}
Properties in current class can be dynamically accessed & updated as follows:
private getTableSessionItems = () => {
var tSession = JSON.parse(sessionStorage.getItem('tableSession'));
if(tSession){
for (var property in tSession) {
if (tSession.hasOwnProperty(property)) {
this[property] = tSession[property];
}
}
console.log('tableSession is true');
}
else{
this.setTableSessionItems();
console.log('nope try again', tSession);
}
}