Error encountered in AngularJS and JSON server: [$injector:unpr] An unidentified provider was found: $resourceProvider <- $resource <- menuFactory

Hello everyone, I recently created a small AngularJS application and utilized a JSON server for my backend operations. Unfortunately, I am encountering an issue with the provider in my code. Upon running it, I am receiving errors as shown below:

Uncaught TypeError: b.module(...).info is not a function at angular-resource.min.js:6 at angular-resource.min.js:14 angular.js:12808 Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- menuFactory http://errors.angularjs.org/1.4.14/$injector/unpr?p0=%24resourceProvider%20%3C-%20%24resource%20%3C-%20menuFactory at at at Object.getService [as get] () at at getService () at invoke () at Object.instantiate () at Object. () at Object.invoke () at Object.enforcedReturnValue [as $get] ()

Below are the codes for my menufactory:

angular.module('confusionApp')
    .constant("baseURL","http://localhost:3000/")

        .service('menuFactory', ['$resource','baseURL', function($resource, baseURL) {

            var promotions = [
                {
                          _id:0,
                          name:'Weekend Grand Buffet', 
                          image: 'images/buffet.png',
                          label:'New',
                          price:'19.99',
                          description:'Featuring mouthwatering combinations with a choice of five different salads, six enticing appetizers, six main entrees and five choicest desserts. Free flowing bubbly and soft drinks. All for just $19.99 per person ',
                }

            ];

                this.getDishes = function () {
                  return $resource(baseURL+"dishes/:id",null, {'update': {'method':'PUT'}});
                };


                this.getPromotion = function (index) {

                    return promotions[index];

                };

        }])

And here is the controller snippet:

angular.module('confusionApp')

    .controller('MenuController', ['$scope', 'menuFactory', function($scope, menuFactory) {

        $scope.tab = 1;
        $scope.filtText = '';
        $scope.showDetails = false;
        $scope.showMenu = true;
        $scope.message = "Loading...";
        $scope.dishes = menuFactory.getDishes().query();
        $scope.select = function(setTab) {
            $scope.tab = setTab;

            if (setTab === 2) {
                $scope.filtText = "appetizer";
            }
            else if (setTab === 3) {
                $scope.filtText = "mains";
            }
            else if (setTab === 4) {
                $scope.filtText = "dessert";
            }
            else {
                $scope.filtText = "";
            }
        };

        $scope.isSelected = function (checkTab) {
            return ($scope.tab === checkTab);
        };

        $scope.toggleDetails = function() {
            $scope.showDetails = !$scope.showDetails;
        };
    }])

This is the routing information:

'use strict';

angular.module('confusionApp', ['ui.router', 'ngResource'])
.config(function($stateProvider, $urlRouterProvider) {
        $stateProvider

            // route for the home page
            .state('app', {
                url:'/',
                views: {
                    'header': {
                        templateUrl : 'views/header.html'
                    },
                    'content': {
                        templateUrl : 'views/home.html',
                        controller  : 'IndexController'
                    },
                    'footer': {
                        templateUrl : 'views/footer.html'
                    }
                }

            })

            // route for the aboutus page
            .state('app.aboutus', {
                url:'aboutus',
                views: {
                    'content@': {
                        templateUrl : 'views/aboutus.html',
                        controller  : 'AboutController'                  
                    }
                }
            })

            // route for the contactus page
            .state('app.contactus', {
                url:'contactus',
                views: {
                    'content@': {
                        templateUrl : 'views/contactus.html',
                        controller  : 'ContactController'                  
                    }
                }
            })

            // route for the menu page
            .state('app.menu', {
                url: 'menu',
                views: {
                    'content@': {
                        templateUrl : 'views/menu.html',
                        controller  : 'MenuController'
                    }
                }
            })

            // route for the dishdetail page
            .state('app.dishdetails', {
                url: 'menu/:id',
                views: {
                    'content@': {
                        templateUrl : 'views/dishdetail.html',
                        controller  : 'DishDetailController'
                   }
                }
            });

        $urlRouterProvider.otherwise('/');
    })
;

Thank you for taking the time to read through.

Answer №1

Have you made sure not to redefine the controller by calling angular.module multiple times with the same module name?

Try only calling angular.module('name') once and then continue building on that returned instance:

var myApp = angular.module('confusionApp') .constant("baseURL","http://localhost:3000/") ....

After that, define your controller like this:

myApp.controller(...)

If this doesn't solve the issue, please provide us with your initial root angular.module definition.

Answer №2

The issue has been successfully resolved. Surprisingly, the problem was not within my code as initially thought. It seems rather illogical, but after using angular.js, angular-ui-router.js, and angular-resource.js from bower, I encountered an error mentioned above. However, upon switching to CDN for these components, the error disappeared and everything started working smoothly again. This indicates that the problem was related to bower rather than my code. It is worth noting that I maintained the same versions of angular.js, angular-ui-router.js, and angular-resource.js both in bower and on the CDN.

Answer №3

The issue might be due to a version mismatch between your Angular and ngResource versions. Your Angular version (1.4) is not compatible with the latest ngResource version (1.6).

If you prefer to stick with your current Angular version, try downloading Angular Resource version 1.4.8. Alternatively, you can specify the exact version number in your bower file by using "angular-resource": "1.5.8" instead of using the caret operator (^) for automatic updates.

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

The Iron Seal feature is ineffective when a user tries to log in

Iron.seal isn't properly updating the npm module Iron, which is causing login issues for users. var obj = { a: 1, b: 2, c: [3, 4, 5], d: { e: 'f' } }; var password = 'some_not_random_password_that_is_at_lea ...

Tips for Implementing a Footer Component in ReactJS

My current setup includes: https://i.stack.imgur.com/2gvHk.png A navigation bar Nested content with a wizard and partial windows. A dynamic footer whose buttons and functionality need to change based on certain scenarios in the content. Currently, I ha ...

I plan to create a program for implementing Gauss Seidel and store each iteration in a single JSON file

Seeking help with creating a program for implementing Gauss Seidel and saving each iteration to JSON. Currently, my code only saves the final iteration, not each one. import json iteration={ "iterasi":None, "x1":0, " ...

JavaScript's Ajax POST request to PHP is not functioning as expected

My current code setup involves handling $_GET[] requests on the products.php page by passing them to get_data_products.php via an ajax POST request. The data retrieved from get_data_products.php is then displayed accordingly. PHP if(isset($_GET['cat ...

Issue with deserializing JSON using GSON

I'm running into an issue with deserializing data using the GSON library. Here's the JSON code I am attempting to deserialize: {"response": { "@service": "CreateUser", "@response-code": "100", "@timestamp": "2010-11-27T15:52:43-08:00", ...

What methods can be used to troubleshoot an issue of an AngularJS function not being called

I am facing an issue with a dynamic table I have created. The rows and action buttons are generated dynamically when the user clicks on the Devices accordion. However, there seems to be a problem with the function expandCollapseCurrent(). Whenever the use ...

Array buffers are scheduled by BinaryJs and the Audio API

My node.js server is streaming some ArrayBuffers: var BinaryServer = require('binaryjs').BinaryServer; var fs = require('fs'); var server = BinaryServer({port: 2000}); server.on('connection', function(client){ var file = f ...

Improve navigation by integrating jQuery validation to resolve input errors seamlessly

I have been working with the jQuery validation plugin and Bootstrap. I recently added a fixed navigation bar at the top of the page using Bootstrap CSS. However, I encountered an issue where the fixed navigation was overlapping with the error message for i ...

What techniques can I employ to ensure that withLatestFrom() effectively interacts with itself?

In my program, I have an intermediate stream that is connected to a source, but it can also trigger events from other sources (such as user input). In another part of my code, there is a derived stream that needs to compare new data from the intermediate w ...

"Utilizing Box elements, implementing linear gradients, styling with CSS, and

Currently, I am working on a project that involves using react JS and I am trying to find a solution for implementing linear gradient in multiple boxes. Specifically, I want to achieve the effect of having three identical boxes lined up next to each other. ...

Is there a way to add additional text to a text element within an SVG?

Is it possible to append a new text element at the end of the data label by clicking on that particular text? I have attempted to implement this in my code but the additional text is not being displayed as expected: circleGroup.selectAll("text") ...

successive ajax requests

I am facing a challenge where I need to execute two separate ajax calls sequentially. The second call relies on the result of the first call for its data. Despite my efforts, I haven't been able to achieve the desired outcome. Here's what I have ...

Implement event listeners to transcluded content in AngularJS

How can I add event handlers to transclusion content in a directive without allowing consumers to add their own click handlers? I want the directive to handle it, but I'm unsure of the correct approach for adding handlers to the content passed with ng ...

The eccentricities of Angular Translate in Firefox and Safari

While everything functions correctly in Chrome, there seems to be an issue with changing the language in Safari and Firefox. angular.module('angularApp') .config(['$translateProvider', function ($translateProvider) { $translateProv ...

What is the best approach to managing numerous files?

I have a couple of .js files: main.js require("./randomEvent.js").begin("hey"); require("./randomEvent.js").begin("hi"); require("./randomEvent.js").begin("hello"); randomEvent.js var repeat = true; exports.begin = (uniqueString) => { while (repe ...

Is the process of adding a new row by duplicating an already existing row dynamic?

I've encountered an issue where a row in a table is not being displayed because the CSS style has been set to display:none. Here's the HTML table: <table class="myTable"> <tr class="prototype"> ........ </tr> </ ...

Utilizing PHP to parse JSON data and showcase the output

I'm currently facing an issue with parsing the data set that I have shared on pastebin at this link http://pastebin.com/TmZGw92j While I am able to navigate through routings, I seem to hit a roadblock when trying to go deeper into the data. Below are ...

Learn how to generate a dynamic pie chart in PHP that can adjust its sections based on the user's input, giving you a fully customizable data visualization tool

let userData = [ { label: "History", data: 90 }, { label: "Science", data: 85 }, { label: "Art", data: 95 }, ]; I have written this javascript code to represent the user's data, but I want it to be more flexible an ...

What is the best way to streamline the creation of a "products filter" using Node.js and Angular?

I have decided to build an angular application for an online computer store, and I am using a node/express backend. One of the key features of the application is the products page, where users can view all the products available in our database. Each produ ...

Sending a POST request to a Flask server using Stripe and AJAX

I am attempting to implement a function that triggers an ajax request when a stripe form is submitted. However, using the .submit() method doesn't seem to be working as expected. Here is my current code: HTML <form action="/download_data" method= ...