angular - Angular2 http.get chaining -


i have following chain of http.get in service:

constructor(private http:http) {}  getdetails(sysid:string){  var details; this.http.get('https://blahurl').map(res => res.json().filter(f => f.id == another.id)[0]).subscribe(     (data) => details = data,             // reach here if res.status >= 200 && <= 299     (err) => console.log(err),            // reach here if fails     function(){                           // on completion        console.log(this);        this.http.get(...) //<- fails 

the "on completion" function gets triggered, this in console safesubscriber object, next http call this.httpfails.

what doing wrong?

use fat arrow syntax retain this value.

replace

function(){  // on completion    console.log(this);    this.http.get(...) //<- fails 

with

()=>{ // on completion    console.log(this);    this.http.get(...)  

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -