In Angularjs, a service is a function or object that can be used in a ANGULARJS application. Where the $location service can return the URL address of the current page. To use it, it needs to be defined in the controller and passed in as a parameter to the controller.
<! DOCTYPE html>
$http Service sends a request to the server to apply the data that the response server transmits.
var app = Angular.module ("myApp", []), App.controller ("Myctrl", Function ($scope, $http) {$http. Get ("welcome.html"). Then (function (response) {$scope. Mywelcome = Response.data;});});
$timeout
var app = Angular.module ("myApp", []), App.controller ("Myctrl", Function ($scope, $timeout) {$scope. MyHeader = "Hello World ", $timeout (function () {$scope. MyHeader =" How is you today? ";},2000);});
Create custom services: You can create custom services and link to your own modules, but when you access a custom service, you need to add and set dependencies independently when you define the controller. When a custom service is connected to its own app, it can be used in a controller/directive/filter or other service.
App.service (' Hexafy ', function () {This.myfunc = function (x) {return x.tostring (16);}}); App.controller (' Myctrl ', function ($scope, Hexafy) {$scope. Hex = Hexafy.myfunc (255);}); App.filter (' MyFormat ', [' Hexafy ', function (hexafy) {return function (x) {return hexafy.myfunc (x);};}]);
Not to be continued ...
ANGULARJS Study notes--services