Santosh Pawar
Santosh Pawar

Reputation: 1

How to store JSON object in a variable?

I have service which is getting the JSON data (object) in the form response. I want to store that JSON object in the storeCrossChannelData variable. How can I achieve this?

this.crossChannelSuccessComparison.getCrossChannelData().subscribe(response=>{
     this.storeCrossChannelData = response
})
console.log(this.storeCrossChannelData);

Upvotes: 0

Views: 231

Answers (1)

Hana Wujira
Hana Wujira

Reputation: 880

the console.log is not displaying the returned value because it is called before the service return the data try calling the console.log inside the subscribe like this

this.crossChannelSuccessComparison.getCrossChannelData().subscribe(response=>{ 
        this.storeCrossChannelData = response
        console.log(this.storeCrossChannelData);
     })

Upvotes: 1

Related Questions