2013-12-08 3 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 }} 
     );  
    } 
} 
관련 문제