Accessing Services and Functions in AngularJS Gadgets
You can define your services, factories, and providers in custom.js.
1. Attach the services, factories, and providers to the gadget module or define them within your own module.
2. Set the dependency of the gadget module to the custom module. If you look up config.js of your gadget, you would find the gadget module defined as below:
var myGadget = angular.module('<MY_GADGET_MODULE>', ['adf.provider',
'MY_GADGET_DIRECTIVE_MODULE'])
.config(){.....
Here MY_GADGET_MODULE refers to the gadget module.
3. Define services, factories, and providers:
Attach services, factories, and providers to
MY_GADGET_MODULE:
MY_GADGET_MODULE.service('<SERVICE_NAME', [<INJECTABLES>,
new ServiceFunction(<INJECTED_OJECTS>){
//Service Code
}]);
Define customised modules:
angular.module("MY_CUSTOM_MODULE",[]).service('<SERVICE_NAME',
[<INJECTABLES>, new ServiceFunction(<INJECTED_OJECTS>){
//Service Code
}]);
Note: Set the dependency of the gadget to MY_CUSTOM_MODULE in the gadgetDefintion.xml to use the service in your gadget. service can be injected into the Controller function using the $inject method. Inject objects of services, factories, and providers in the init method of the Controller in order.