Thursday, November 5, 2015

AngularJS - What is factory method?

Ref:- http://www.tutorialspoint.com/angularjs/angularjs_interview_questions.htm

Using factory method, we first define a factory and then assign method to it.

var mainApp = angular.module("mainApp", []);
mainApp.factory('MathService', function() {     
   var factory = {};  
  
   factory.multiply = function(a, b) {
      return a * b 
   }
   return factory;
}); 

No comments:

Post a Comment