Usage
$http (config);
Arguments
Config
Object describing the request to is made and how it should is processed. The object has following Properties:method–{string}–http method (e.g. ' get ', ' POST ', etc) url–{string| Trustedobject}–absolute or relative URL of the resource is being requested; Or an object created by a call to $sce. Trustasresourceurl (URL). Params–{object.<string| Object>}–map of strings or objects which'll is serialized with the Paramserializer and appended as get parameters. Data–{string| Object}–data to is sent as the request message Data.
Example
var req = {method
: ' POST ',
URL: ' http://example.com ',
headers: {
' content-type ': Undefined
},
data: {test: ' Test '}
}
$http (req). Then (function () {...}, function () {...});
Excerpted from angular1.x official website: https://docs.angularjs.org/api/ng/service/$http
The Settings object can contain the following primary keys:
①method
Can be: get/delete/head/jsonp/post/put
②url: Absolute or relative request target
③params (String map or object)
The value of this key is a string map or object that is converted to a query string appended to the URL. If the value is not a string, it is serialized by JSON.
?
④data (string or object)
This object contains data that will be sent to the server as a message body. Typically used when sending a POST request.
Starting with Angularjs 1.3, it can also send binary data in a POST request. To send a Blob object, you can simply pass it by using the data parameter.
?
Using $http in the controller
var app = Angular.module (' app ', [' Ngtouch ', ' Ui.grid ', ' ui.grid.resizeColumns ', ' ui.grid.moveColumns ']);
App.controller (' Mainctrl ', [' $scope ', ' $http ', function ($scope, $http) {
$scope. gridoptions = {
enablesorting : True,
columndefs: [
{field: ' Name ', minwidth:200, width:250, enablecolumnresizing:false},
{field: ' Gen Der ', Width: ' 30% ', maxwidth:200, minwidth:70},
{field: ' Company ', Width: ' 20% '}
]
};
$http. Get ('/data/100.json ')
. Success (function (data) {
$scope. gridoptions.data = data;
});
Excerpt from Angular UI grid:http://ui-grid.info/docs/#/tutorial/204_column_resizing
Get the data and filter the data
$http. Get ('/data/100.json ')
. Success (function (data) {
Data.foreach (function setgender (row, index) {
Row.gender = row.gender=== ' male '? ' 1 ': ' 2 ';
});
$scope. gridoptions.data = data;}
])
. Filter (' Mapgender ', function () {
var genderhash = {
1: ' Male ',
2: ' Female '
};
return function (input) {
if (!input) {return
";
} else {return
genderhash[input];
}};
});