ANGULARJS Introduction:
Angularjs extends HTML through new properties and expressions.
Angularjs can build a single page application (Spas:single page applications).
Angularjs is very easy to learn.
The ANGULARJS can be customized in three ways ($provider, $factory, $service), and the following are different implementation forms:
Define module, injected into module $provide var starterapp = angular.module (' starter.controllers ', [],function ($provide) {//The first way: Custom Service $provide with provide provider. Provider (' Getuserinfoservice ', function () {this. $get = function () {var userInfo = [{]
UserName ': ' 30 ', ' Usernick ': ' Floret 0 ', ' age ': '},{' userName ': ' Zhang 31 ', ' Usernick ': ' Floret 1 ', ' Age ': 26}];
return userInfo;
}
});
$provide. Factory (' ", function () {});
$provide. Service (' ", function () {});
}); The second approach (injected $provide in the Config method of module) starterapp.config ([' $provide ', function ($provide) {///provide provider custom service ( Returns the object, string, service, and must be returned through the $get method $provide. Provider (' Getuseraddressservice ', function () {var _useraddress = '; var service = {
}; this. $get = function () {service.setaddress = function (useraddress) {_useraddress = useraddress;} service.getaddress = Fu
Nction () {return _useraddress;} return service;
}
});
Use provide's factory custom service (return object, Service, String) $provide. Factory (' serviceName1 ', [' $http ', function ($http) {//var service = {}; Service.getname = FunctiOn () {//return ' John ';//}//return service;
Return "Ah whispering big";
}]); Use provide service custom services (returns objects, services) $provide. Service (' serviceName2 ', [' $http ', function ($http) {//return {//' name ': '
AA '//};
You can define method This.getname = function () {return ' John ';}} directly via this.
}]); The Third Way (module's provider, service, factory method recommends a third) Starterapp.provider (' ServiceName3 ', function () {this. $get =
function () {return ' defines the service ' directly through the provider method of module;
Starterapp.factory (' ServiceName4 ', function () {return ' defines service directly through module's factory method ';}); Starterapp.service (' ServiceName5 ', function () {return {' message ': ' Define services directly through module's service method '}});
The above is a small set to introduce the ANGULARJS custom service three ways summary, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!