I think you want to do something like this:

return new Observable<string>((observer: Observer<string>) => {

    this.http.post(...)
        .map(res => res.json())
        .do((data) => {
            ... all that code in the callback goes here ...
        })
    .map((data) => data.token)
    .subscribe(observer);
});

If you need more help, I suggest you create a plunkr.

-Luke

On Tue, Aug 2, 2016 at 12:26 PM, Rafael Gouveia da silva <
[email protected]> wrote:

> Thanks Lucas,
>
> It's because I saved the data in localStorage, as it passes first in line
> 44, the login I have to do the operation twice, for only the second can
> access the data token, any suggestions?
>
> Em terça-feira, 2 de agosto de 2016 12:12:53 UTC-4, Lucas Lacroix escreveu:
>>
>> That is absolutely correct.
>> The code at line 32 is a callback that is invoked asynchronously. Line 44
>> will always be hit first.
>>
>> On Tue, Aug 2, 2016 at 11:42 AM, Rafael Gouveia da silva <
>> [email protected]> wrote:
>>
>>>
>>> <https://lh3.googleusercontent.com/-GrjaN7drb8k/V6C-hWJXrbI/AAAAAAAAE1E/td08We9P3bgy0n11R0tC-EPoNYrkNrl5QCLcB/s1600/Sem%2Bt%25C3%25ADtulo.png>
>>>
>>>
>>> I am a begginer, I have a doubt when I debug.
>>> Because the breakpoint , first passes through line 44, and then the 32 ?
>>>
>>> --
>>> 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 [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.
>>>
>>
>>
>>
>> --
>> 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 [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.
>



-- 
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 [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