Example of Creating Basic Factory and Service in AngularJS

[code] mainApp2.factory(‘MathService’, function() { var factory = {}; factory.multiply = function(a, b) { return a * b; }; return factory; }); mainApp2.service(‘CalcService’, function(MathServic){ this.square = function(a) { return MathService.multiply(a,a); }; }); mainApp2.controller(‘CalcController’, function($scope, CalcService) { $scope.square = function() { $scope.result = CalcService.square($scope.number); }; }); [/code] [code] <div ng-app=”mainApp2″ ng-controller=”CalcController”> <p>Enter a number: <input type=”number” ng-model=”number”

Read More