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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -