Hey everyone,

I'm working on getting a json object array using an http get request. 
Currently, I have a list-view.component that calls a function, getEvents() 
in my event.service component. That function returns Promise<Event[]>, 
which represents the object array. It successfully returns the updated 
array to list-view.component, but for some reason, when I try to print out 
the array on console, it doesn't show the changes.

list-view.component.ts 

this.eventService.getEvents(lat, lon, range, s).then(events => this.eventsList 
= events);

console.log(this.eventsList);


event.service.ts 

getEvents(lat: number, lon: number, radius: number, s: string): 
Promise<Event[]> {
    return this.http.get(this.eventsUrl + "?s=" + s +"&radius=" + radius + 
"&lat=" + lat + "&lon=" + lon)
        .toPromise()
        .then(response => response.json() as Event[])
        .catch(this.handleError);
  }


If I try to print the array in the .then method, like below, it prints it 
correctly. 

this.eventService.getEvents(lat, lon, range, s).then(events => 
console.log(events));


How come, when I try to print it after the this.eventService.getEvents() 
call, it doesn't have the new changes?

-- 
You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to