我无法在AngularJS中获得服务

时间:2013-12-28 15:43:08

标签: javascript angularjs

我的问题在下一段代码中描述:

var eventModule = angular.module('eventModule', ['ngResource']);

eventModule.factory('Event', ['$resource',
    function($resource){
        return $resource('http://cip-cirip.ro/API/events/:eventId', {}, {
          query: {method:'GET', params:{eventId:'55'}, isArray:false}
        });
    }
]);

eventModule.controller('events_interface', function ($scope, $http){
    //$scope.events = [{id:1, name:'evenimentul 1'},{id:2, name:'evenimentul 2'}];
    var ev = Event();
    console.log(ev);
    $scope.events = ev.query();
});

1 个答案:

答案 0 :(得分:2)

您需要将服务作为依赖项注入,无论您何时需要访问它:

eventModule.controller('events_interface', function ($scope, $http, Event){...