inject one provider in other in angularjs -
i new angularjs , trying calculate square , cube of number using providers. first provider mtprovider
in i've declared 4 functions , in other provider calservice
, declared 2 functions in using functions of mtprovider
provider.
i want use functions of mtprovider
in calservice
.
angular.module("myapps", []) .provider("mtprovider", function() { return{ $get : function() { return{ add : function(a, b){ return a+b; }, substract : function(a, b){ return a-b; }, multiply : function(a, b){ return a*b; }, divide : function(a, b){ return / b; } }; } }; }) .provider("calservice",['mtprovider',function(mtprovider) { return{ $get : function() { return{ square : function(a) { return mtprovider.multiply(a, a); }, cube : function(a) { return mtprovider.multiply(a, mtprovider.multiply(a, a)); } } }; } }]) .controller("mycontroller", function($scope, calservice){ $scope.squarenumber = function() { $scope.answer = calservice.square($scope.number); } $scope.cubenumber = function() { $scope.answer = calservice.cube($scope.number); } });
Comments
Post a Comment