如何发送变量函数角度服务?

时间:2013-12-08 15:31:38

标签: javascript angularjs

如何从控制器发送变量 year,monthGet 函数角度服务?

服务

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) {
});

1 个答案:

答案 0 :(得分:2)

您的工厂函数只能由应用程序注入器实例化一次(调用/新建):您需要这样做:

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 }}
        );    
    }
}