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

                      Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                      Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                      How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page