The error message in angular.js line 13294 indicates a problem with an unknown provider called cityResourceProvider, which is required by cityResource and cityListCtrl

I'm having my first experience with angularJS and trying to use services and factories to create a web api REST call. I encountered this error message even before making the call:

angular.js:13294 Error: [$injector:unpr] Unknown provider: cityResourceProvider <- cityResource <- cityListCtrl

app.js

(function() {
    "use strict";

    angular.module("politicalHub",["common.services"]);

}());

common.services.js

(function() {
    "use strict";

    angular.module("common.services", ["ngResource", "ngRoute"])
        .constant("appSettings", {
            serverPath: "http://localhost:49828/"
        });
});

cityResource.js

(function() {
    "use strict";

    function cityResource($resource, appSettings) {
        return $resource(appSettings.serverPath + "api/City");
    }

    angular
        .module("common.services", [])
        .factory("cityResource",
        [
            "$resource",
            "appSettings",
            cityResource
        ]);
}());

cityListCtrl.js (Controller)

(function() {
    "use strict";
    function cityListCtrl(cityResource) {
        var vm = this;

        cityResource.query(function(data) {
            vm.cities = data;
        });
    }

    angular
        .module("politicalHub",[])
        .controller("cityListCtrl",
        ["cityResource", cityListCtrl]);


}());

html

 <form>
              <div ng-controller="cityListCtrl as vm" align="center">
                  <div class="col-lg-12" style="padding: 0">
                      <select ng-options="city.city_name for city in cities" ng-model="city.name" class="form-control">

                      </select>
                  </div>
              </div>
          </form>

Any help on this issue would be greatly appreciated!

Answer №1

It appears that you forgot to invoke the common.services.js file, as its IIFE function should execute automatically.

(function() {
    "use strict";

    angular.module("common.services", ["ngResource", "ngRoute"])
        .constant("appSettings", {
            serverPath: "http://localhost:49828/"
        });
})();

Answer №2

Here is the solution that worked for me:

(function() {
    "use strict";

   var app = angular.module("politicalHub",["common.services"]);

}());

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

Adjust the color of a contenteditable div once the value matches

I currently have a table with some contenteditable divs: <div contenteditable="true" class="change"> This particular JavaScript code is responsible for changing the color of these divs based on their content when the page loads. However, I am now ...

Is it possible to customize the close icons on the autocomplete feature in Material UI?

Is there a solution to change the icon while keeping its function when clicked? I am looking to replace this Icon <Autocomplete multiple id="checkboxes-tags-demo" options={top100Films} disableCloseOnSelect getOpt ...

Having trouble with gsap.reverse() not functioning properly when using onMouseLeave event in React

I've been incorporating simple gsap animations into my React application. I have successfully triggered an animation.play() function on onMouseEnter, but for some reason, the animation.reverse() function is not functioning as expected. Here's ho ...

Tips for utilizing multiple CSS styles in JavaScript

My goal is to apply multiple CSS styles to a button with the id of name_button. Below is the JavaScript code I have written: var name_button = document.getElementById('name_button'); name_button.style.display = 'block'; name_button.st ...

Child component in Angular failing to trigger change event in list

In my current project, I have a parent component responsible for making an AJAX call to fetch data from the backend to populate a grid. To render the grid data, I created a child component where I pass the list as an in-binding. However, I noticed that whe ...

Is there a way to eliminate the pop-up window background in MUI?

Is there a way to get rid of the white pop-up background in MUI's default CSS? <Dialog open={open} onClose={() => { setOpen(false); }} > <DialogContent> <h1>Do you really ...

Is the asynchronous nature of setState truly reliable?

As I delve into learning React, an interesting topic that keeps popping up is the async nature of setState. It's often mentioned that if you try to console.log(state) immediately after calling setState, it will display the old value instead of the upd ...

Tips for resolving the issue with TypeError: arr[Symbol.iterator] not being a function in my React application

I am facing an issue while trying to follow this tutorial. Although I have diligently followed the code provided, I seem to be encountering an error that the tutorial creator did not experience. This problem arose at the 2:09:30 mark in the tutorial. Afte ...

When using jQuery Ajax, only pass the query string if it is defined and not empty

Using jquery and ajax to communicate with a CMS API, I am constructing a query string to fetch data: region = typeof region !== 'undefined' ? 'region='+region : ''; centre = typeof centre !== 'undefined' ? 'cen ...

Please provide values in the input box, with each value separated by

I attempted the following code: success: function (result) { for (var i = 0; i < result.d.length; i++) { var emails = new Array(); emails = result.d[i].Emailid; alert(emails); $("#EmailCC").val(emails); ...

How can you simulate an error response with $httpBackend in Angular?

I am currently running tests to ensure that my program handles HTTP request error messages correctly. However, I am facing a challenge trying to simulate this scenario using $httpBackend. The code snippet I have is: $httpBackend.expectGET(path).respond(40 ...

Ways to extract Document ID from a Firestore database collection

Currently, I am in the process of developing a mobile app using React Native and Firebase. My main focus right now is on accessing document data without explicitly specifying the ID, unlike the method shown below: const docRef = db.collection('vehicle ...

Is there a way to customize the appearance of an unordered list by setting it to display as an image instead of default bullets? I want to

I have been attempting to achieve this desired outcome. However, my efforts to reproduce it resulted in the check marks being rendered at a smaller size than intended due to using an SVG file. An example of this issue can be seen in the following image: I ...

Is there a way to disable the useMutation function once it has successfully completed its

Greetings, I am facing an issue with the mutation below: export const useUserSearch = (data) => { return useMutation({ mutationKey: ["user-search", data], mutationFn: fetchUser, }); }; I have implemented it in my component as foll ...

Having trouble converting a string to an array in JS? Splitting doesn't seem to be doing

I encountered an issue where I am reading data from a CSV file, storing the innerHTML to a variable (named content), which the browser recognizes as a string. However, when attempting to convert it to an array, I am facing difficulties. I attempted to use ...

Unable to assign an ID to an event in Angular when the eventReceived event is triggered

I am currently working with the Angular fullcalendar module that includes drag and drop functionality. My goal is to assign an ID to new events dropped on the calendar by users, but I am unsure of the proper way to do this. Here is the Stackblitz link. Ad ...

How can an Express.js server detect when a browser has been closed or reloaded?

Currently tackling a project with an Express.js server. One query I have is how can this server detect when one of its users (browser) has been closed or reloaded? Any insights on this would be greatly appreciated! ...

A foolproof method for confirming an object is an EcmaScript 6 Map or Set

Can someone help me verify if an object is a Map or Set, but not an Array? For checking an Array, I currently use lodash's _.isArray. function myFunc(arg) { if (_.isArray(arg)) { // doSomethingWithArray(arg) } if (isMap(arg)) { // doS ...

What is the best way to generate a new component by triggering an event with Vue.js?

Imagine you have a list of posts retrieved from an ajax response, and now you want to provide users with the option to edit any specific post by clicking a button. One approach could be using the v-show directive to attach a form component to each post. Wh ...

Displaying an 'undefined' message in a JavaScript alert box

Hello! Just made the switch from C#/C++ to JavaScript recently and I'm really enjoying it. I've encountered a behavior that has me scratching my head, can anyone help explain? So here's what's happening: when I run this script, I see ...