The console.log is executed before the asynchronous operation (ie.
".subscribe") invokes the callbacks.

On Fri, Jul 29, 2016 at 11:18 AM, Josh Restivo <josh.rest...@4resti.com>
wrote:

> I've tried various incarnations of the following function and can't get
> 'this.entries' to return with any data (it's always undefined in the
> console log). I'm clearly not understanding how to handle the observable
> correctly and am hoping for some guidance...
>
> ...
>
> import * as x2js from 'xml2js';
>
> ...
>
>
>
> getPosts() {
>
>
> this.parser = x2js.parseString;
>
>
> this.http.get(this.url)
> .map((res:Response) => {
> this.parser(res);
> })
> .subscribe(
> data => { this.entries = data },
> err => console.error(err)
> );
> console.log("entries: ", this.entries);
> }
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+unsubscr...@googlegroups.com.
> To post to this group, send email to angular@googlegroups.com.
> Visit this group at https://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Lucas Lacroix
Computer Scientist
System Technology Division, MEDITECH <http://ehr.meditech.com>
781-774-2293

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

Reply via email to