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
-1
votes
1 answer

AngularJs populate second dropdown based on first dropdown

I have two select input, first one contain countryName, i want to populate the StateName to the second select input depending on the CountryName that is chosen i.e the stateName for the selected country only. I bind the countryName from the…
-1
votes
3 answers

How to make simple http Post using Ionic-framework?

I am trying to make a simple POST request for sign in but it doesn't work. I read this thread (AngularJs $http.post() does not send data) and tried almost every suggestion but nothing works. Here is my…
charbinary
  • 1,875
  • 4
  • 17
  • 25
-1
votes
2 answers

Problems using $http POST

I am new in angular.js and I need to make form with 2 fields for numbers and when I click on submit i need to send to server with json for request result of suma. It will look like: 4 in first field , 4 in second field and on submit it will return…
Sasa Geric
  • 57
  • 1
  • 1
  • 4
-1
votes
2 answers

How can I display json data return from the controller using angularjs

I want to display the json encode data return from the controller using angularjs to my view.
Search …
PHP.Newbie
  • 195
  • 1
  • 4
  • 16
-1
votes
2 answers

What's the best way to constantly watch for any changes on JSON using Angular?

Through the following code, I'm loading JSON once: $http.get('/data').success(function(mydata) { $scope.mydata = mydata; }); I would like to watch for any changes coming from JSON and then reload the new data so I can update the $scope and…
trs
  • 863
  • 2
  • 16
  • 35
-1
votes
1 answer

How do Angular HttpPromises work?

I want to use Angular's $http but I'm not sure what to do with what it returns. The main thing that is troubling me is that it returns an HttpPromise. What do I do with that? How does it work?
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
-1
votes
2 answers

Why am I able to execute an $http function just by adding .success to it?

I created a factory that returns an $http promise. loginRsrc.factory('loginSrvc', ['$http', function($http){ var http = $http({ method: 'POST', url: "http://myproj.herokuapp.com/api/signIn", data: $.param({email:…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
-1
votes
1 answer

No 'Access-Control-Allow-Origin' ---> Doing an angular $HTTP request

I am doing a an ajax get request and I am getting this error: XMLHttpRequest cannot load http://domains.bootname.com/api/v1/domain/test. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is…
fresh5447
  • 1,242
  • 3
  • 14
  • 27
-1
votes
1 answer

How to use binding parameters in $http service?

I need to make ajax request. I can do this: var categoryId = 152; var url = "/someurl/category/"+categoryId; $http.get(url); Is it possible to use binding with $http? Something like: $http.get("/someurl/category/:categoryId", {categoryId: 152});
Sharikov Vladislav
  • 7,049
  • 9
  • 50
  • 87
-1
votes
1 answer

Getting $http.put() to send correctly formatted data, instead of JSON object

So, I spent some time and built a quick API for a project that I'm doing for myself. I used the Postman add-on for Chrome to mimic PUT and DELETE quests to make sure everything worked correctly. Really happy I did that, as I learned a lot about…
Jhecht
  • 4,407
  • 1
  • 26
  • 44
-1
votes
1 answer

Angular post method

I've created a http method in a service. But when i call it, it returns null and i can't figure out why. Here is the method: objectResponse.httpCall = function ( sMethodName, postData){ var rData = null; $http({ dataType: "json", …
-1
votes
1 answer

How can I build a get request with url that contains parameters

I am trying to do a get request to recover data from the server using the following url: url = /api/projects/:projectId/scenarios How can I do that using $http.get in AdngularJS?.
Adrian Espinoza
  • 73
  • 2
  • 10
-2
votes
1 answer

Using the angular httpclient i receive this error TypeError: Cannot read properties of undefined (reading 'get')

I have to make an http request via Angular but the error written in the title appears whether I use 'post' or 'get' as if the http variable was undefined or uninitialized. I checked the module and is imported correctly import { NgModule } from…
-2
votes
2 answers

Why http://localhost:4200 is appended to HttpClient API?

I am working with Angular7. When I make API call Angular application URL also appended to the URL const payload = { id: 1, name: 'ABC }; const httpOptions = { headers: new HttpHeaders({ 'Content-Type':…
Gnik
  • 7,120
  • 20
  • 79
  • 129
-2
votes
1 answer

how http, httpClient, httpModule and httpClientModule differ with each other?

Can you please let me know how http, httpClient, httpModule and httpClientModule differ with each other? which among them are depricated and supported versions of each of them.
mahesh peddi
  • 787
  • 3
  • 8
  • 21
1 2 3
64
65