The service itself is an arbitrary object, and the service process that NG provides involves its dependency injection mechanism.
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title></title></Head><Body> <DivNg-app= "MYAPP"> <DivNg-controller= "Firstcontroller">{{name}}</Div> </Div><Scripttype= "Text/javascript"src=".. /.. /vendor/angular/angularjs.js "></Script><Scripttype= "Text/javascript"src= "App/index.js"></Script></Body></HTML>
var myApp = angular.module (' myApp ', [],function ($provide) { // Custom Service $provide. Provider (' Customservice ',function () { thisfunction () { return{ ' Customservice Message '}}} }); Myapp.controller (' firstcontroller ',function ($scope, Customservice) { = ' Alrale '; Console.log (Customservice);});
- Angular uses $provide object to implement the automatic dependency injection mechanism, and the injection mechanism invokes a provider $get () method to invoke the resulting object as a parameter.
- $provide. Provider () is a method of defining a service, $provide also provides a number of simple methods that can be referenced directly by the module. More using factory, the server method
ANGULARJS[13]-Define the provider method in the service $provide