Handle data after http get request in angularHow do I return the response from an asynchronous call?How do I share data between components in Angular 2?What's the difference between a POST and a PUT HTTP REQUEST?How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?How to manage a redirect request after a jQuery Ajax callHTTP GET request in JavaScript?Is an entity body allowed for an HTTP DELETE request?HTTP GET with request bodymaximum length of HTTP GET request?How to use java.net.URLConnection to fire and handle HTTP requestsHow is an HTTP POST request made in node.js?How are parameters sent in an HTTP POST request?

What should you do when eye contact makes your subordinate uncomfortable?

Why is it that I can sometimes guess the next note?

Multiplicative persistence

C++ debug/print custom type with GDB : the case of nlohmann json library

On a tidally locked planet, would time be quantized?

How to bake one texture for one mesh with multiple textures blender 2.8

Travelling outside the UK without a passport

Loading commands from file

Can I sign legal documents with a smiley face?

Where does the bonus feat in the cleric starting package come from?

"Spoil" vs "Ruin"

How much character growth crosses the line into breaking the character

How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?

When were female captains banned from Starfleet?

It grows, but water kills it

Fear of getting stuck on one programming language / technology that is not used in my country

What if a revenant (monster) gains fire resistance?

What does chmod -u do?

Creepy dinosaur pc game identification

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

What is this called? Old film camera viewer?

Biological Blimps: Propulsion

How to explain what's wrong with this application of the chain rule?

Did Swami Prabhupada reject Advaita?



Handle data after http get request in angular


How do I return the response from an asynchronous call?How do I share data between components in Angular 2?What's the difference between a POST and a PUT HTTP REQUEST?How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?How to manage a redirect request after a jQuery Ajax callHTTP GET request in JavaScript?Is an entity body allowed for an HTTP DELETE request?HTTP GET with request bodymaximum length of HTTP GET request?How to use java.net.URLConnection to fire and handle HTTP requestsHow is an HTTP POST request made in node.js?How are parameters sent in an HTTP POST request?













0















I have a service that requests data from a get method, I'd like to map the response to an object storing some Ids and use those Ids to make other http requests.
I was told this isn't usually done in a callback manner, I looked at this How do I return the response from an asynchronous call? but I don't think it's the usual way to implement services, any hints are very appreciated.



Tried adding in onInit/constructor method in angular to be sure the object was filled before other methods were called without success.



@Injectable ()
export class ContactService {
storeIds;

getIds(callback: Function)
this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
callback(response);
);

getIds(res =>
this.storeIds =
profileId: res.profile,
refIds: res.refIds


)

// this.storeIds returns undefined as it's an async call
this.http.post<any>(WebserviceUrl + this.storeIds.profileId , data, headers )

// .....Many other web services that relay on this Ids










share|improve this question






















  • what is your problem? what issue you are facing in which line of your code?

    – Bear Nithi
    Mar 8 at 4:49











  • Do you want chain of remote calls after getting the response from getIds call? I didnt understand that part. Or is that you want to put the response you got somewhere so that you can use it for future api calls. Can you make it clear?

    – santosh
    Mar 8 at 4:52












  • I want to store this Ids somewhere for future api calls, without having to enter in a bunch of callbacks to access them.

    – Jaime FH
    Mar 8 at 4:57











  • Are u going to make all those calls from contact service or from other services? I just wanted to know if you want this response data outside the contact service?

    – santosh
    Mar 8 at 5:06











  • Yes the intention is to call it from other services as ´this.myService.postSomething(data, callback)´ having this id's already existing

    – Jaime FH
    Mar 8 at 5:08















0















I have a service that requests data from a get method, I'd like to map the response to an object storing some Ids and use those Ids to make other http requests.
I was told this isn't usually done in a callback manner, I looked at this How do I return the response from an asynchronous call? but I don't think it's the usual way to implement services, any hints are very appreciated.



Tried adding in onInit/constructor method in angular to be sure the object was filled before other methods were called without success.



@Injectable ()
export class ContactService {
storeIds;

getIds(callback: Function)
this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
callback(response);
);

getIds(res =>
this.storeIds =
profileId: res.profile,
refIds: res.refIds


)

// this.storeIds returns undefined as it's an async call
this.http.post<any>(WebserviceUrl + this.storeIds.profileId , data, headers )

// .....Many other web services that relay on this Ids










share|improve this question






















  • what is your problem? what issue you are facing in which line of your code?

    – Bear Nithi
    Mar 8 at 4:49











  • Do you want chain of remote calls after getting the response from getIds call? I didnt understand that part. Or is that you want to put the response you got somewhere so that you can use it for future api calls. Can you make it clear?

    – santosh
    Mar 8 at 4:52












  • I want to store this Ids somewhere for future api calls, without having to enter in a bunch of callbacks to access them.

    – Jaime FH
    Mar 8 at 4:57











  • Are u going to make all those calls from contact service or from other services? I just wanted to know if you want this response data outside the contact service?

    – santosh
    Mar 8 at 5:06











  • Yes the intention is to call it from other services as ´this.myService.postSomething(data, callback)´ having this id's already existing

    – Jaime FH
    Mar 8 at 5:08













0












0








0








I have a service that requests data from a get method, I'd like to map the response to an object storing some Ids and use those Ids to make other http requests.
I was told this isn't usually done in a callback manner, I looked at this How do I return the response from an asynchronous call? but I don't think it's the usual way to implement services, any hints are very appreciated.



Tried adding in onInit/constructor method in angular to be sure the object was filled before other methods were called without success.



@Injectable ()
export class ContactService {
storeIds;

getIds(callback: Function)
this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
callback(response);
);

getIds(res =>
this.storeIds =
profileId: res.profile,
refIds: res.refIds


)

// this.storeIds returns undefined as it's an async call
this.http.post<any>(WebserviceUrl + this.storeIds.profileId , data, headers )

// .....Many other web services that relay on this Ids










share|improve this question














I have a service that requests data from a get method, I'd like to map the response to an object storing some Ids and use those Ids to make other http requests.
I was told this isn't usually done in a callback manner, I looked at this How do I return the response from an asynchronous call? but I don't think it's the usual way to implement services, any hints are very appreciated.



Tried adding in onInit/constructor method in angular to be sure the object was filled before other methods were called without success.



@Injectable ()
export class ContactService {
storeIds;

getIds(callback: Function)
this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
callback(response);
);

getIds(res =>
this.storeIds =
profileId: res.profile,
refIds: res.refIds


)

// this.storeIds returns undefined as it's an async call
this.http.post<any>(WebserviceUrl + this.storeIds.profileId , data, headers )

// .....Many other web services that relay on this Ids







ajax angular http get






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 4:39









Jaime FHJaime FH

3218




3218












  • what is your problem? what issue you are facing in which line of your code?

    – Bear Nithi
    Mar 8 at 4:49











  • Do you want chain of remote calls after getting the response from getIds call? I didnt understand that part. Or is that you want to put the response you got somewhere so that you can use it for future api calls. Can you make it clear?

    – santosh
    Mar 8 at 4:52












  • I want to store this Ids somewhere for future api calls, without having to enter in a bunch of callbacks to access them.

    – Jaime FH
    Mar 8 at 4:57











  • Are u going to make all those calls from contact service or from other services? I just wanted to know if you want this response data outside the contact service?

    – santosh
    Mar 8 at 5:06











  • Yes the intention is to call it from other services as ´this.myService.postSomething(data, callback)´ having this id's already existing

    – Jaime FH
    Mar 8 at 5:08

















  • what is your problem? what issue you are facing in which line of your code?

    – Bear Nithi
    Mar 8 at 4:49











  • Do you want chain of remote calls after getting the response from getIds call? I didnt understand that part. Or is that you want to put the response you got somewhere so that you can use it for future api calls. Can you make it clear?

    – santosh
    Mar 8 at 4:52












  • I want to store this Ids somewhere for future api calls, without having to enter in a bunch of callbacks to access them.

    – Jaime FH
    Mar 8 at 4:57











  • Are u going to make all those calls from contact service or from other services? I just wanted to know if you want this response data outside the contact service?

    – santosh
    Mar 8 at 5:06











  • Yes the intention is to call it from other services as ´this.myService.postSomething(data, callback)´ having this id's already existing

    – Jaime FH
    Mar 8 at 5:08
















what is your problem? what issue you are facing in which line of your code?

– Bear Nithi
Mar 8 at 4:49





what is your problem? what issue you are facing in which line of your code?

– Bear Nithi
Mar 8 at 4:49













Do you want chain of remote calls after getting the response from getIds call? I didnt understand that part. Or is that you want to put the response you got somewhere so that you can use it for future api calls. Can you make it clear?

– santosh
Mar 8 at 4:52






Do you want chain of remote calls after getting the response from getIds call? I didnt understand that part. Or is that you want to put the response you got somewhere so that you can use it for future api calls. Can you make it clear?

– santosh
Mar 8 at 4:52














I want to store this Ids somewhere for future api calls, without having to enter in a bunch of callbacks to access them.

– Jaime FH
Mar 8 at 4:57





I want to store this Ids somewhere for future api calls, without having to enter in a bunch of callbacks to access them.

– Jaime FH
Mar 8 at 4:57













Are u going to make all those calls from contact service or from other services? I just wanted to know if you want this response data outside the contact service?

– santosh
Mar 8 at 5:06





Are u going to make all those calls from contact service or from other services? I just wanted to know if you want this response data outside the contact service?

– santosh
Mar 8 at 5:06













Yes the intention is to call it from other services as ´this.myService.postSomething(data, callback)´ having this id's already existing

– Jaime FH
Mar 8 at 5:08





Yes the intention is to call it from other services as ´this.myService.postSomething(data, callback)´ having this id's already existing

– Jaime FH
Mar 8 at 5:08












2 Answers
2






active

oldest

votes


















1














Just create another service called StoreIdsService. Update the response you get from your first api call 'getIds' in the StoreIdsService. The idea is to have StoreIdsService as singleton service to keep state of your storeIds. You can inject StoreIdsService in anywhere component you want to get the storeIds.



Its one of manyways to share data in angular between components.



Please refer to this answer someone has posted.



How do I share data between components in Angular 2?






share|improve this answer






























    0














    You can simply assign the service response to the storeIds property inside the subscribe method. and call the subsequent services inside it if you need.



    @Injectable ()
    export class ContactService {
    storeIds;

    getIds()
    this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
    this.storeIds =
    profileId: response.profile,
    refIds: response.refIds


    this.otherapicall1();
    this.otherapicall2();
    );







    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056828%2fhandle-data-after-http-get-request-in-angular%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Just create another service called StoreIdsService. Update the response you get from your first api call 'getIds' in the StoreIdsService. The idea is to have StoreIdsService as singleton service to keep state of your storeIds. You can inject StoreIdsService in anywhere component you want to get the storeIds.



      Its one of manyways to share data in angular between components.



      Please refer to this answer someone has posted.



      How do I share data between components in Angular 2?






      share|improve this answer



























        1














        Just create another service called StoreIdsService. Update the response you get from your first api call 'getIds' in the StoreIdsService. The idea is to have StoreIdsService as singleton service to keep state of your storeIds. You can inject StoreIdsService in anywhere component you want to get the storeIds.



        Its one of manyways to share data in angular between components.



        Please refer to this answer someone has posted.



        How do I share data between components in Angular 2?






        share|improve this answer

























          1












          1








          1







          Just create another service called StoreIdsService. Update the response you get from your first api call 'getIds' in the StoreIdsService. The idea is to have StoreIdsService as singleton service to keep state of your storeIds. You can inject StoreIdsService in anywhere component you want to get the storeIds.



          Its one of manyways to share data in angular between components.



          Please refer to this answer someone has posted.



          How do I share data between components in Angular 2?






          share|improve this answer













          Just create another service called StoreIdsService. Update the response you get from your first api call 'getIds' in the StoreIdsService. The idea is to have StoreIdsService as singleton service to keep state of your storeIds. You can inject StoreIdsService in anywhere component you want to get the storeIds.



          Its one of manyways to share data in angular between components.



          Please refer to this answer someone has posted.



          How do I share data between components in Angular 2?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 5:20









          santoshsantosh

          1289




          1289























              0














              You can simply assign the service response to the storeIds property inside the subscribe method. and call the subsequent services inside it if you need.



              @Injectable ()
              export class ContactService {
              storeIds;

              getIds()
              this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
              this.storeIds =
              profileId: response.profile,
              refIds: response.refIds


              this.otherapicall1();
              this.otherapicall2();
              );







              share|improve this answer



























                0














                You can simply assign the service response to the storeIds property inside the subscribe method. and call the subsequent services inside it if you need.



                @Injectable ()
                export class ContactService {
                storeIds;

                getIds()
                this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
                this.storeIds =
                profileId: response.profile,
                refIds: response.refIds


                this.otherapicall1();
                this.otherapicall2();
                );







                share|improve this answer

























                  0












                  0








                  0







                  You can simply assign the service response to the storeIds property inside the subscribe method. and call the subsequent services inside it if you need.



                  @Injectable ()
                  export class ContactService {
                  storeIds;

                  getIds()
                  this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
                  this.storeIds =
                  profileId: response.profile,
                  refIds: response.refIds


                  this.otherapicall1();
                  this.otherapicall2();
                  );







                  share|improve this answer













                  You can simply assign the service response to the storeIds property inside the subscribe method. and call the subsequent services inside it if you need.



                  @Injectable ()
                  export class ContactService {
                  storeIds;

                  getIds()
                  this.http.get<any>(IdsUrl, Config.options).subscribe(res =>
                  this.storeIds =
                  profileId: response.profile,
                  refIds: response.refIds


                  this.otherapicall1();
                  this.otherapicall2();
                  );








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 5:05









                  Bear NithiBear Nithi

                  2,664723




                  2,664723



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056828%2fhandle-data-after-http-get-request-in-angular%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme