What is service method?

Service method in AngularJS helps you to define service and method to it. In the following example, we have injected a simple addition service, which adds two numbers.

Event Registration

Guru99 Global Event

Result: {{result}}

var mainApp = angular.module(“mainApp”, []);
mainApp.service(‘AdditionService’, function(){
this.ADDITION = function(a,b) {
return a+b;
}
});

mainApp.controller(‘DemoController’, function($scope, AdditionService) {

$scope.result = AdditionService.ADDITION(5,6);
});

Leave a Reply