Search code examples
angularobjectangular2-servicesangular2-directives

accessing specific values from Objects in angular 2


i have a function in my angular 2 project

this.fetchedData=  this._visitService.getchartData().toPromise();
console.log("WORKING I HOPE0", this.fetchedData)` 

which gives the output:

WORKING I HOPE0 
ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
__zone_symbol__state:true
__zone_symbol__value:Array(2)
0:{date: "2018, 03, 14", value: 11}
1:{date: "2018, 03, 15", value: 1}
length:2
__proto__:Array(0)
__proto__:Object`

Is it possible to access __zone_symbol__value to get it whole as an object or even just retrieve data from it. I tried using console.log("WORKING I HOPE0", this.fetchedData.__zone_symbol__value) but it doesn't seem to work. I am not looking for any alternate way of doing it. So if I wanted to know if its possible or not and why or why not.


Solution

  • I think you should do it like :

    this._visitService.getchartData().toPromise().then(data => {
        this.fetchedData = data;
        console.log(data);
    })
    

    For your queries as per the comment , try this :

    this._visitService.getchartData().toPromise().then(data => {
        this.fetchedData = data;
        console.log(data);
        this.processFetchedData(); // call the function once this.fetchedData is initialized
    })
    
    processFetchedData(){
        console.log(this.fetchedData); // check the console
    }