I am currently working on an Angular application with a C# backend that exposes services. I am trying to use AngularJS resources to access these services. However, when I call the resource in the controller, I am encountering 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
This 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);
});
This 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 researched various solutions to similar issues, but none seem to address this specific problem.
Thank you in advance.