How to use Named Parameters in Angularjs $http?

Asked

Viewed 57 times

0

Is there any way to use named parameters in the method $http angular?

With ngResource it is possible to do this:

var User = $resource('/path/to/user/:id');
$scope.user = User.get({id: 1}, function() {
   $scope.user.name = $scope.user.first_name + ' ' + $scope.user.last_name;
});

Someone knows a way to do this in the method $http?

1 answer

0

$http.get('/someUrl').

URL = 'api/controler/action?parameter1=xxx&parameter2=xxx' - in the case of a webapi2, it depends on the type of server you are consuming.

$http.post('/someUrl', {msg:'hello word!'}).
      then(function(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

The Response Object has These properties:

data - {string|Object} - The Response body Transformed with the Transform functions.

status - {number} - HTTP status code of the

Response. headers - {Function([headerName])} - Header getter Function.

config - {Object} - The Configuration Object that was used to generate

the request. statusText - {string} - HTTP status text of the Response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.