Currently, I am in the process of developing an angular application. In this project, there is a specific scenario that needs to be handled where a parameter is undefined.
Here's a snippet of my code:
myImage() {
console.log('test')
console.log(typeof(this.ahuObservables.on_off_status))
this.myValue = this.myObservables.status
console.log(typeof(this.myValue))
if (this.myValue == null)
{
console.log('undefined')
this.ahuValue = 0
}
else{
// do something
}
getDataRealTime()
{
console.log('Making a request')
this.SocketService.socket_connection()
.subscribe(
(data1: any) => {
console.log(data1)
let data11 = JSON.parse(data1)
this.myObservables = new My_Observables()
this.myObservables.status = data11['status']
console.log('variables parsed')
}
)
}
The value of this.myObservables.status
is fetched from an API call. Therefore, when the API is unavailable, I need the myValue
variable to default to 0. I have attempted to check for null and undefined values but have been unsuccessful in setting a default value when myObservables.status
is undefined. Additionally, the second console log statement isn't displaying anything in the console. Can anyone provide assistance?
Thank you.