AngularJS introduction:
AngularJS extends HTML with new properties and expressions.
AngularJS can build a single page application (SPAs: Single Page Applications).
AngularJS is very easy to learn.
In angularjs, you can customize services through three ways ($provider,$factory,$service). The following are different implementation forms:
// Define module , inject $providevar starterApp = angular.module('starter.controllers', [],function($provide){// The first method: use the provide provider to customize the service $provide.provider('getUserInfoService', function(){this.$get = function(){var userInfo = [{'userName':'Zhang San0','userNick':'Xiaohua0','age':25},{'userName':'Zhang San1','userNick':'Xiaohua1','age':26}];return userInfo;}});$provide.factory('',function(){});$provide.service('',function(){});});//The second method (inject $provide into the config method of module)starterApp.config(['$provide',function($provide) {// Use the provider to customize the service (return 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 = function (){return _userAddress;}return service;}});// Customize the service using the factory provided (return object, service, string)$provide.factory('serviceName1', ['$http', function($http){// var service = {};// service.getName = function (){// return 'Zhang San';// }// return service;// return "Ah sarsada";}]);// Use the service provider to customize the service (return object, service)$provide.service('serviceName2', ['$http', function($http){// return {// 'name':'aa'// };// You can directly define the method this.getName = function (){return 'Zhang San';}}])}]);//The third method (the third method of module provider, service, factory method is recommended) starterApp.provider('serviceName3',function(){this.$get = function (){return 'Direct service directly through the provider method of module';}});starterApp.factory('serviceName4',function(){return 'Direct service directly through the factory method of module';});starterApp.service('serviceName5',function(){return {'message':'Direct service directly through the service method of module'}});The above is a summary of three ways of Angularjs custom service introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!