Thursday, 15 May 2014

angularjs - Angular factory and its functions calling each other -



angularjs - Angular factory and its functions calling each other -

how can refer function within factory? here example, want function2 utilize function1 while returning result (which fails is):

angular.module('myapp'). factory('examplefactory', function ($http, $rootscope) { homecoming { function1: function (a,b) { homecoming + b; }, function2: function (a,b,c) { homecoming this.function1(a,b) * c }, } })

here 1 alternative using "revealing module" design pattern:

angular.module('myapp'). factory('examplefactory', function ($http, $rootscope) { function function1 (a,b) { homecoming + b; } function function2 (a,b,c) { homecoming function1(a,b) * c; } homecoming { function1: function1, function2: function2, } });

angularjs factory

No comments:

Post a Comment