0

I'm just getting into using Angular (using version 7.2.2) after starting to dislike jquery mobile.

I'm a bit confused of how to get the JSON response from a post request using the http client, this is what I have so far:

this.http.post(this.appService.getWPEndPoint('content/dashboard'),null,{})

I've seen different examples using something called "pipe" and another "subscribe"... but they are all confusing.

In jQuery I would just do this:

$.post(URL,OPTIONS,function(response){
},'json');

I just want to do this same sort of thing in angular but I can't figure out here how to get the response like I would in jQuery; can someone point me in the right direction please?

Glen Elkins
  • 867
  • 9
  • 30
  • Hello, what does that 7 in the title refer to? keep in mind AngularJS refers to Angular 1.x – dawsnap Jun 25 '19 at 15:07
  • @daviddd What do you mean? It refers to AngularJS version 7?? according to my package.json file which says this: "@angular/common": "^7.2.2", - is that not AngularJS 7.2.2 ?? It's really confusing learning angular, I've just read that AngularJS is the first version of Angular? So am I using Angular 7 here then? Which is also confusing because my version says 7.2.2 but all I find online is Angular 1 or 2, what? – Glen Elkins Jun 25 '19 at 15:22
  • AngularJS is used to refer to AngularJS (Angular 1.x). You're using Angular 7 – dawsnap Jun 25 '19 at 15:26
  • 1
    Ok, I'll update my question, thanks. – Glen Elkins Jun 25 '19 at 15:26
  • 1
    Possible duplicate of [How do I return the response from an Observable/http/async call in angular?](https://stackoverflow.com/questions/43055706/how-do-i-return-the-response-from-an-observable-http-async-call-in-angular) – Igor Jun 25 '19 at 15:33
  • 1
    See the suggested duplicate. `HttpClient` calls return `Observable`s which you can subscribe to. While you are at it I would read over the answer to this question as well, [How do I return the response from an asynchronous call?](https://stackoverflow.com/q/14220321/1260204). This answer should help you better understand how to work with asynchronous calls in javascript and by extension typescript / angular. – Igor Jun 25 '19 at 15:34
  • 2
    Side-note for OP, ignore tutorials that mention needing to convert to JSON using something like `.map(res => res.json())` : that's a signal that *the tutorial is old because we don't do that any more.* – msanford Jun 25 '19 at 15:36

0 Answers0