Questions tagged [angular-http]

AngularJS tag for $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

For unit testing applications that use $http service, see $httpBackend mock.

For a higher level of abstraction, please check out the $resource service.

The $http API is based on the deferred/promise APIs exposed by the $q service. While for simple usage patterns this doesn't matter much, for advanced usage it is important to familiarize yourself with these APIs and the guarantees they provide.

General usage

The $http service is a function which takes a single argument — a configuration object — that is used to generate an HTTP request and returns a promise with two $http specific methods: .then and .catch.

// Simple GET request example :
$http.get('/someUrl')
  .then(function(response) {
    var data = response.data;
    // this callback will be called asynchronously
    // when the response is available
}).catch(function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
// Simple POST request example (passing data) :
$http.post('/someUrl', {msg:'hello word!'})
  .then(function(response) {
    // this callback will be called asynchronously
    // when the response is available
}).catch(function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

Since the returned value of calling the $http function is a promise, you can also use the then method to register callbacks, and these callbacks will receive a single argument – an object representing the response. See the API signature and type info below for more details.

A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning that the error callback will not be called for such responses.

970 questions
-2
votes
2 answers

Angular 6 cannot get item from array

I am building app which shows amazon products : showProducts(){ this.search.getProducts().subscribe ((data: any) => { this.list = data['hydra:member']; this.prices = data.lowestPrices.Amazon.newItem; …
Angulandy2
  • 786
  • 4
  • 13
  • 31
-2
votes
1 answer

No 'Access-Control-Allow-Origin' header is present on the requested resource while accessing a local server by angular app

I was trying to get results from a local server. The class which I am using in the service is as follows: @Injectable() export class GridSearchService { server = 'http://127.0.0.1:8100'; searchURL = this.server +…
bro33
  • 117
  • 2
  • 7
-2
votes
1 answer

When is subscribe method of Angular Http module called

I have a component class and service class. I have the logic of flipping a flag when http 200 status code is received. Based on the response received, I flip the flag using an if condition. Requests(data:Array):Observable{ return…
DP3
  • 108
  • 6
  • 19
-2
votes
1 answer

How to write service in angular 2

My Component: getDetailsByPhone(phone: any) { this.phoneSearchDetails = this.appService.manageHttp('get', 'search?number='+phone, ''); } My service: manageHttp(method: any, url: any, body: any) { this.headers =…
MMR
  • 2,869
  • 13
  • 56
  • 110
-2
votes
2 answers

Unable to access json data in angularjs array

I've successfully returned a json object which has query results from database. I'm unable to access the returned json one by one. Here's what the console.log shows: Angular code: $scope.peopleList=[]; …
Jaskaran Singh Puri
  • 729
  • 2
  • 11
  • 37
-2
votes
1 answer

Why AngularJS is changing values of the objects?

My AngularJS service code - this.getEducation = function (id) { var url = 'SOME_URL/?party_id=' + id; var deferred = $q.defer(); $http.get(url). success(function (data, status, headers, config)…
-3
votes
1 answer

Data is being sent via $http to php file but JSON decodes blank or undefined?

I am using $http through AngularJS to send data to a PHP document which is intended to save the data in a MySQL database. However, the data is being decoded blank or undefined. The JSON makes it to the PHP file, as I can see the request headers, but…
Matthew Walker
  • 193
  • 1
  • 15
-3
votes
1 answer

Parsing remote resource in Angular

In Angular 5, what do I need to consider regarding CORS, when accessing a remote resource via http.get()? EXAMPLE: let url = `http://www.google.com`; this.http.get(url).subscribe(res => { console.log(res.text()); // parse…
Ben
  • 15,938
  • 19
  • 92
  • 138
-3
votes
2 answers

Pulling data from website with angular 6 get requests

I'm trying to pull JSON files from the web and I am doing something wrong. Here is my code: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http' import { Observable } from 'rxjs'; @Injectable({ …
Vladimir_314159
  • 1,457
  • 1
  • 9
  • 21
-5
votes
2 answers

Angularjs :- how to get funtion's response using $http.get()?

I am new in anggular js. I have a test.html page. test.html
harish
  • 13
  • 6
1 2 3
64
65