Angularjs methods for obtaining service port data (three): $http, $resource, Restangular. In addition breeze can also refer to (ODATA)
Where: $http, with restangular return promise.
Promise is an object that takes a function as the then property value:
Then (Fulfilledhandler, ErrorHandler, Progresshandler)
After adding Fulfilledhandler, ErrorHandler, and Progresshandler, the Promise object is formed. Fulfilledhandler is called when promise is loaded with data, ErrorHandler is called when promise fails, and Progresshandler is invoked when the progress event is triggered. All parameters are optional, and non-function parameters are ignored. Sometimes Progresshandler is not just an optional parameter, but the progress event is a purely optional argument. The implementation of the promise pattern does not necessarily call Progresshandler every time (because it can be ignored), and only when this parameter is passed in will it occur.
This method returns a new Promise object after the Fulfilledhandler or ErrorHandler callback is completed. In this way, the promise operation can form a chained call. The return value of the callback handler is a Promise object. If the callback throws an exception, the returned Promise object will set the state to fail.
==========================
Use the built-in service $http of Angulasrjs to get server-side data examples in the controller :
var app = Angular.module (' Metronicapp ');
App.controller(' Appctrl ', function Appctrl ($scope, $http, restangular) {
(function getusers () {
var webapi = "/api/userss"; Access to the server where the program resides, omitting DNS, and access to its domain requires a full address.
$http. Get (WEBAPI)//Get data relative to the address
. Success (function (response, status, headers, config) {//Processing on success
var data = new Wijmo.collections.ObservableArray (response);
$scope. Users = new Wijmo.collections.CollectionView (data);
})
. Error (Function (response, status, headers, config) {//processing on failure, status on state code 403, etc.!
Console.log (' request error: ' + Webapi);
alert (page);
});
});
})();
}
============
Same service-side access using: Restangular
var app = Angular.module (' Metronicapp ');
App. Config (restangularprovider) {//configure the underlying routing path
Restangularprovider.setbaseurl ('/api ');
});
App.controller (' Appctrl ', function Appctrl ($scope, restangular) {//inject restangular service
(function getusers () {//This functions immediately executed, you can omit ...
Restangular.one ("Users"). GetList (). Then (function (data) {
$scope. Users = new Wijmo.collections.CollectionView (data);
}, function (err) {
Console.log (' request error: ' + err);
Alert ("Request error-----okkkkkk!");
});
})();
}
Angularjs methods for obtaining service port data---$http, $resource, Restangular