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?
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
|
show 2 more comments
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
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
|
show 2 more comments
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
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
ajax angular http get
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
|
show 2 more comments
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
|
show 2 more comments
2 Answers
2
active
oldest
votes
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?
add a comment |
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();
);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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?
add a comment |
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?
add a comment |
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?
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?
answered Mar 8 at 5:20
santoshsantosh
1289
1289
add a comment |
add a comment |
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();
);
add a comment |
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();
);
add a comment |
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();
);
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();
);
answered Mar 8 at 5:05
Bear NithiBear Nithi
2,664723
2,664723
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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