2013-12-08 25 views
1

如何發送變量年,月獲得功能從控制器的角度服務?如何發送變量函數角度服務?

服務

myApp.factory('getJsonForCalendarService', function($resource, year, monthGet) { 

     return $resource(
      '../rest/api.php', 
      { method: 'getJsonForCalendar', year: year, monthGet:month}, 
      {'query': { method: 'GET', isArray: true }} 
     ); 

}); 

控制器

$scope.getJsonForCalendar = getJsonForCalendarService.query(function (response, year, monthGet) { 
}); 

回答

2

你的工廠函數只會被實例化(被稱爲/ newed)一旦被應用注射器:你需要這樣做:

myApp.factory('getJsonForCalendarService',function($resource){ 
    return function(year,month){   
     return $resource(
      '../rest/api.php', 
      { method: 'getJsonForCalendar', year: year, monthGet:month}, 
      {'query': { method: 'GET', isArray: true }} 
     );  
    } 
}