Ole Bark
Ole Bark

Reputation: 109

angular REST get ID only from call

I want to do a call then get the ID from that call and use it in some code later but how do I only get the ServiceProvider number? this is what I get from my rest call:

     {"mitId": 18,
     "ServiceProvider": "2"}

this is my current call

  GetServiceProviderId() {
    var spid = this.http.get<Info>(this.rooturl + 'info', { headers: this.reqHeader})

    return spid;
  }

So I want to use the ServiceProvideNumber in another call but how do I only return the 2?

Upvotes: 0

Views: 1096

Answers (2)

Ole Bark
Ole Bark

Reputation: 109

I ended up doing this:

  GetServiceProviderId(): Observable<Info> {
    return this.http.get<Info>(this.rooturl + 'info', { headers: this.reqHeader })
  }

this just returns the json request I then will use pipe and flatmap to get the '2'

  GetInstallation(): Observable<Installation[]> {
    return this.GetServiceProviderId().pipe(
      flatMap(info => {
        return this.http.get<Installation[]>
          (this.rooturl +
          "url/?serviceproviderid=" +
          info.ServiceProviderId
      })
    )
  }

this will make the call api/url/?serviceproviderid=2

Upvotes: 0

Anshuman Jaiswal
Anshuman Jaiswal

Reputation: 5462

Return observable from method GetServiceProviderId as:

GetServiceProviderId() {
    return this.http.get<Info>(this.rooturl + 'info', { headers: this.reqHeader});
}

Subscribe to consume value from response wherever you want as:

GetServiceProviderId.subscribe(res => {
    console.log(res);
    //here you will get id
})

Upvotes: 1

Related Questions