flatMap is not working in Angular2

310
December 01, 2017, at 07:25 AM

Hello guys i just created a simple ajax call in which the response of first ajax call is used in second ajax call so i used flatmap in angular 2 to run first ajax call and use its response in second ajax call here is the code but only the first ajax call is working properly it seems like the code after .flatmap isnt running. please help me to solve this issue.

createPerson(personClass: User, addressClass: Address): Rx.Observable <string> { 
  let headers = new Headers(); 
  headers.append('Content-Type', 'application/json'); 
  headers.append("Cache-Control", "no-cache"); 
  headers.append("Cache-Control", "no-store"); 
  headers.append("If-Modified-Since", "Mon, 26 Jul 1997 05:00:00 GMT"); 
  var myObj = { 
    "firstName": personClass.firstname, 
    "age": personClass.age, 
    "lastName": personClass.lastname, 
    "dateOfBirth": "null" 
  }; 
 
  return this.http.post(`${webServiceEndpoint}/person`, JSON.stringify(myObj), { 
      headers: headers 
    }).map((res: Response) => res.json()) 
    .flatMap(data => { 
      let body = data.json(); 
      console.log(body); 
      var myObj2 = { 
        "personId": body, 
        "address1": addressClass.streetname, 
        "city": addressClass.city, 
        "zipCode": addressClass.zipcode 
      }; 
 
      return this.http.post(`${webServiceEndpoint}/address`, JSON.stringify(myObj2), { 
        headers: headers 
      }).map((res1: Response) => res1.json()) 
    }) 
}

Answer 1

As data is not a Response object this may be failing:

let body = data.json();
READ ALSO
How to get an array with all pictures?

How to get an array with all pictures?

I'm working to upload images, everything works great, but I have 100 pictures and I would like to show them all in my view, as I get the complete list of the images in a folder, I can not find in the new api this option

266
Spotify get size of a playlist for android

Spotify get size of a playlist for android

I'm using the Spotify API to play a Spotify playlist on my appI'd like to find the number of tracks in the playlist, but can't find anything in the docs to give me this

254
jersey/tomcat Description The origin server did not find a current representation for the target resource

jersey/tomcat Description The origin server did not find a current representation for the target resource

I have configured jersey (with tomcat server) according to the details described until step 63 here: http://www

2473
Elastic Search 5.6.4 pom transport issue

Elastic Search 5.6.4 pom transport issue

We are pointing to Elasticsearch 56

227