Rectangle 27 0

angularjs How to call "Angular JS" service method using string variable?


$scope.serviceList=["yearDetails","monthDetails","dayDetails"];

//controller
$scope.getDetails=function(type,index){

    if(type==$scope.serviceList[index]){

     //now i can able to call my service through injector in angular
     var $inj = angular.element('html').injector();
     var serv = $inj.get($scope.serviceList[index]);
     serv.query(function(data){
            console.log(data);
     });
    }
}

//service
.factory('yearDetails', function($resource){
           return $resource('/getyearDetails', {}, {
               query: { method:'POST', params:{}, isArray:false }
   });
})
.factory('monthDetails', function($resource){
           return $resource('/getmonthDetails', {}, {
               query: { method:'POST', params:{}, isArray:false }
   });
})
.factory('dayDetails', function($resource){
           return $resource('/getdayDetails', {}, {
               query: { method:'POST', params:{}, isArray:false }
   });
})
Note