Method not found in Angular

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.

Answer №1

It appears that the problem may lie in the minification of your code. Make sure to declare your controllers and services in a minification-friendly manner.

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


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

}]);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to prevent the context menu from appearing when tapping on an image on a mobile phone?

When attempting to move an image on the screen with a touch event, a popup appears in Chrome when pressing and holding the image. This popup usually includes options to save the image. Is there a way to disable this popup so I can freely move the image w ...

Exploring the potential of Bootstrap/bootflat and jQuery progress bars

I am attempting to display and animate a progress bar while loading an HTML page into a div using jQuery. The progress bar I am using is from Bootstrap (Bootflat) and has the following structure: <div class="progress" style="visibility:hidden;"> ...

Browser freezes unexpectedly every 10-15 minutes

I have an application that displays 10 charts using dygraphs to monitor data. The charts are updated by sending ajax requests to 4 different servlets every 5 seconds. However, after approximately 10-15 minutes, my browser crashes with the "aw! snap" messag ...

Vanilla JavaScript - Conceal all remaining div elements

I have a situation where multiple divs are only visible after clicking a link. How can I ensure that when one div is clicked, all others are closed so that only the clicked one remains visible? Currently, I am using the following JavaScript: functio ...

Does AngularJS have a callback function for ng-bind-html-unsafe?

Is there a way to efficiently remove certain elements from the DOM after they have been added by this code snippet? <div ng-bind-html-unsafe="whatever"></div> I have created a function to remove these elements, but I am unsure how to trigger ...

Determining the appropriate version of the types package for your needs

It has come to my attention that certain npm packages do not come with types included. Because of this, the community often creates @types/packagename to provide those types. Given that both are packages, how does one determine which version of the types ...

Could someone please assist me with an issue I am experiencing with an AJAX GET request?

My code is not fetching any data for me. Below is the code snippet: <script type="text/javascript"> function matriculaFn(mat) { $.ajax({ method: 'GET', url:'My url API, async: true, crossDomain: false, contentType: 'application/j ...

Utilizing v-if and splice on users to select items from v-model

After following a tutorial, I have the code snippet below that I would like to enhance: <div style="margin-top: 10px;"> v-for="task in taskItems" :key="task.id" <q-icon :name="task.icon"/> <div ...

"Troubleshooting: Why are errors not appearing in ts-node

Whenever I encounter an error in my code while compiling with ts-node, the error does not seem to appear in the console. For instance:let data = await fs.readFileSync(path); In the following code snippet, I am using "fs" to read a file by passing a path ...

Tips for Adding For Loop Value to an Array in JavaScript

Trying to Add For Loop Value to an Array My Current View <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script> <style> body { font-family: Roboto, sans-serif; } #chart { max-width: 650px; margin: 35px auto; ...

Utilizing object property in angular's ng-model directive

After defining a class, instantiating it and assigning the object to scope, I encountered an issue with ng-model references. Despite setting everything up correctly, the code isn't working as expected. I have a hunch that Angular might not be compatib ...

A helpful guide on how to dynamically input database values into the href attribute of an 'a' tag

How do I successfully pass an ID to href in my code? When I try to return it via req.params, it keeps coming back as undefined. I need the ID from the URL in order to use the findOne method to access the data stored in the database. I've searched thr ...

AngularYelp: Node Integration for Enhanced Functionality

Embarking on a new learning journey here, so please bear with me... Discovered node-yelp while browsing Yelp's API docs. Check it out here. // Request API access: http://www.yelp.com/developers/getting_started/api_access var Yelp = require('yel ...

Sending data from a parent component to a child component through a function

In the process of developing an app, I have implemented a feature where users must select options from four dropdown menus. Upon clicking the "OK" button, I aim to send all the selections to a child component for chart creation. Initially, I passed the sel ...

What are some potential causes of webpack-dev-server's hot reload feature not working properly?

Having an issue with my React project. When I try to use hot reload by running "npm start" or "yarn start" with webpack-dev-server configured (--hot flag), I'm getting the error message: [error message here]. Can anyone assist me in troubleshooting th ...

Vue 3's click event handler does not recognize $options.x as a valid function

I'm encountering a perplexing issue. I am currently in the process of creating a Wordpress plugin using Vue, but unfortunately, I am unable to establish functionality for the @click event. <script> export default { name: "App", me ...

Passing a Ruby session variable to a JavaScript tag: a step-by-step guide

I'm currently collaborating with a vendor who utilizes a JavaScript tag for sale attribution, and I need to pass session variables to the tag. The tag appears to be firing properly, as I can see the variables in the logs, but they aren't reflecte ...

Is there a way to retrieve the initial value from the second element within the JSON data?

Exploring JSON Data Collections In my JSON data, I have two collections: FailedCount and SucceededCount. { "FailedCount": [{ "FailedCount_DATE_CURRENT_CHECK": "2016-11-30 10:40:09.0", "FailedCount_DATE__CURRENT__CHECK": "10:40:09", "FailedCo ...

Mongoose: Enhancing Arrays with maximum values for each item

How to Update an Array Property in Mongoose with Item-Wise Max and Default Null Upon Instantiation I have a MongoDB collection that stores time series data in a fixed-length array (1 item per minute, 1 document per day). { 'series': '#1& ...

Retrieve the data stored in a JSON object

After making an ajax call, the json object that gets returned looks like this: Object {0: "1", 1: "jake", 2: "#00ff00", tip_id: "1", tip_details: "jake", tip_color: "#00ff00"} Object {0: "2", 1: "jakee", 2: "#00ff00", tip_id: "2", tip_details: "jakee", t ...