0

Im currently building an angular application that has a C# backend that expose services. I want to use angularjs resources to access those services. When in the controller I call the resource I'm getting the following error:

TypeError: Object function g(b){z(b||{},this)} has no method 'getCourse'
    at new <anonymous> (http://127.0.0.1:81/ClientApp/controllers/CourseIndex.js:6:36)
    at d (http://127.0.0.1:81/Scripts/angular/angular.min.js:30:352)
    at Object.instantiate (http://127.0.0.1:81/Scripts/angular/angular.min.js:30:482)
    at http://127.0.0.1:81/Scripts/angular/angular.min.js:59:495
    at http://127.0.0.1:81/Scripts/angular/angular.min.js:47:450
    at p (http://127.0.0.1:81/Scripts/angular/angular.min.js:7:367)
    at U (http://127.0.0.1:81/Scripts/angular/angular.min.js:47:342)
    at k (http://127.0.0.1:81/Scripts/angular/angular.min.js:42:309)
    at k (http://127.0.0.1:81/Scripts/angular/angular.min.js:42:326)
    at http://127.0.0.1:81/Scripts/angular/angular.min.js:41:371 

Here is my controller:

coursewareApp.controller('CourseIndex', function ($scope, $location, Courses) {
    $scope.courseOutline = Courses.getCourse(); //Error in this line
    $scope.courseOutline.then(
        function(course) {
            $scope.courseOutline = fixFormat(course);
        },
        function(response) {
            console.log(response);
        });

Here is my service:

coursewareApp.factory('Courses', function ($resource, $q) {
    var resource = $resource('/api/Block', {},
                    {
                        getCourse: {
                            method: 'GET',
                            headers: { 'Authorization-Token': '6A594741380806DF128E28BDCC072859A1ECF0DC24478DDD890CC191C8357AFF12F837F657104E285BE8E2151F8631D148DEF89420024EDAA71DDB8404A1C1947ABD2BBE8002952DC891246CADCB1D452F445E773AB0CE8B4B9CF566A738ED7736AFC66B61FBFDCD59EDD68D2F8F4D5FF31DA0DD8F0CA98C10CA07F18C1C386462D0D2694385DA38C9F6C2A04B15B885AEBDF917E155014942040272E0F36B2D4E39303CBC430738902CF75093EAD11492AA87A9' },
                            url: '/api/Block/Courses',
                        }
                    });
    return {
        getCourse: function () {
            var deferred = $q.defer();
            resource.getCourse(
                function(event) {
                    deferred.resolve(event);
                },
                function(response) {
                    deferred.reject(response);
                });
            return deferred.promise;
        }
    };
});

I have read many solutions to similar problems but none of them seem to apply to this.

Thanks in advance.

4

1 回答 1

2

这似乎是一个缩小问题尝试以缩小友好的方式声明您的控制器\服务

coursewareApp.controller('CourseIndex', ['$scope', '$location', 'Courses',function ($scope, $location, Courses) {
}]);


coursewareApp.factory('Courses', ['$resource','$q',function ($resource, $q) {

}]);
于 2014-01-10T03:34:28.017 回答