Translate Primary tillage in English; Translate Primary tillage in Arabic; Translate Primary tillage in Chinese (s) Translate Primary tillage in Chinese (t) Translate Primary tillage in Dutch; Translate Primary tillage in French; Translate Primary tillage in German; Translate Primary tillage in Greek; Translate Primary tillage in Hebrew
Thus service is a stateless object that contains some useful functions. These functions can be called from anywhere; Controllers, Directive, Filters etc. Thus we can divide our application in logical units. The business logic or logic to call HTTP url to fetch data from server can be put within a service object.
Hereâs a basic module, service, and controller in Angular: angular.module('myApp.service',[]); angular.module('myApp',['myApp.service']); var StatesController = function($scope) {}. On the first line is a service named âmyApp.serviceâ. Note that the dot is not necessary, nor is using the app name as a prefix. I could have named it âgoferâ if I wanted. The important part is that I let the main application module know the name, which brings me to line 2, the main module. The main module names the app and gives it a a comma delimited reference to services, filters, etc. that can be referenced. If I defined a filter named âmyApp.filterâ my module definition would have been: âangular.module(âmyAppâ,[âmyApp.serviceâ,âmyApp.filterâ]);â. The module name, âmyAppâ, will be used in my ngApp directive in the template. Line 3 is the shell of a controller definition which will be directly accessible by the template.