Angular 2 http get not getting

Http uses rxjs and is a cold/lazy observable, meaning that you should subscribe to it to make it work. this.http.get(`http://swapi.co/api/people/1`) .map((response: Response) => { console.log(response.json()); response.json(); }) .subscribe(); Or if you want to subscribe from somewhere else, you should return the http.get method like this: getAllPersons(): Observable <any> { console.log(“Here”); return this.http.get(`http://swapi.co/api/people/1`) .map((response: Response) => … Read more

Processing $http response in service

Here is a Plunk that does what you want: http://plnkr.co/edit/TTlbSv?p=preview The idea is that you work with promises directly and their “then” functions to manipulate and access the asynchronously returned responses. app.factory(‘myService’, function($http) { var myService = { async: function() { // $http returns a promise, which has a then function, which also returns a … Read more

How can I post data as form data instead of a request payload?

The following line needs to be added to the $http object that is passed: headers: {‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’} And the data passed should be converted to a URL-encoded string: > $.param({fkey: “key”}) ‘fkey=key’ So you have something like: $http({ method: ‘POST’, url: url, data: $.param({fkey: “key”}), headers: {‘Content-Type’: ‘application/x-www-form-urlencoded; charset=UTF-8’} }) From: https://groups.google.com/forum/#!msg/angular/5nAedJ1LyO0/4Vj_72EZcDsJ UPDATE To … Read more