Error: [$injector:unpr] Oh no! The AuthServiceProvider Angular Service seems to be MIA

I am currently working on a small AngularJS project and encountering an issue with my service files not being successfully injected into the controllers. I have double-checked for any syntax errors, but despite trying different variations, the problem persists:

Service:

(function (){

'use strict';

  angular
    .module('tooltipEditorFrontEndApp')
    .factory('AuthService', AuthService);

    AuthService.$inject = ['$window', 'Restangular'];

    function AuthService($window, Restangular) {

      var exports = {
        setAuthHeader: setAuthHeader
      };

      function setAuthHeader() {
        if ($window.sessionStorage.getItem('token')) {
          var token = angular.fromJson($window.sessionStorage.getItem('token')).token;
          Restangular.setDefaultHeaders({ 'Authorization': 'Token '+token });
        }
      }

      return exports;

    }

})();

Controller:

(function (){

'use strict';

  angular
    .module('tooltipEditorFrontEndApp')
    .controller('MainController', MainController);

    MainController.$inject = ['$scope', '$window', 'Restangular', 'AuthService'];

    function MainController($scope, $window, Restangular, AuthService) {

      var test;

      AuthService.setAuthHeader();

      test = Restangular.all('states');

      test.getList().then(function(states) {
        $scope.states = Restangular.stripRestangular(states);
      });
    }

})();

Load scripts:

<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script scr="scripts/services/auth.service.js"></script>
<script src="scripts/controllers/main.controller.js"></script>
<script src="scripts/controllers/login.controller.js"></script>
<script src="scripts/controllers/about.controller.js"></script>
<!-- endbuild -->

Answer №1

After removing and reinstalling Angular version 1.4.1 in the project, the service is now functioning correctly.

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

Utilizing NodeJS code and the SlackAPI to build a custom chatbot named PFBot

Recently, I came up with an idea for a Slack Bot that could censor inappropriate language used by users. For example, if a user types a curse word, the bot would automatically replace it with symbols based on the length of the word. Although I'm rela ...

Receiving data from multiple sockets in Node.js with Socket.io

I recently started working with Node.js to develop an online game that acts as a server-side application. This application serves the .html and .js files to the client while managing the game's logic. I'm utilizing Socket.io for communication bet ...

Display a webpage embedded within another webpage as a pop-up

Is there a way to open a HTML page within another HTML page when a button is clicked? I'm looking to have this displayed in a popup with the main HTML page as the background. Any suggestions on how I can achieve this? ...

AngularJS table with resizable columns for seamless data browsing

Most examples of expandable tables using ng-repeat feature a separate content for the expanded row, like an independent table inside the detail row. I have implemented many expandable tables using these methods, similar to the following: <tr ng-repeat ...

Is there a way to access the active request being processed in a node.js environment?

I am currently working with express.js and I have a requirement to log certain request data whenever someone attempts to log a message. To accomplish this, I aim to create a helper function as follows: function logMessage(level, message){ winston.log(le ...

Bug detected in the brfs plugin for browserify

I'm currently working on a project where I need to consolidate all the .html template files into a single bundle.js file by reading the content from each .html file. In my main.js, I have written the following code: var fs = require('fs'); ...

Enhance User Experience with JQuery Autocomplete for Internet Explorer 8 Using ASMX Web Services

Help Needed! I have been trying to implement a Web Service (ASMX) file on my website. When I access and query the page, I receive the desired results. The problem arises when I attempt to add autocomplete functionality to a textbox in my ASP.NET applicati ...

Issue with Tanstack React Query failing to import

Attempting to integrate tanstack react query into my current project to handle state management has proven challenging. Following a tutorial on using react query with nextjs 13, I thought I was following it correctly. However, I encountered various import ...

Guide on enabling automatic rotation using Javascript

Recently, I came across a slider online that unfortunately did not have an autorotate feature. Despite my attempts to add an autorotate function using setTimeout and click functions, I was unsuccessful. This particular slider contains 4 buttons for each s ...

I am experiencing an issue where my JavaScript code does not redirect users to the next page even

I'm experiencing an issue with this code where it opens another webpage while leaving the login screen active. I've tried multiple ways to redirect it, such as window.location.href and window.location.replace, but nothing seems to be working. Ide ...

Sending messages on Discord.js at one-minute intervals

Hey there, I'm currently facing an issue while trying to automate a message sending process on Discord. The specific error that keeps popping up is: bot.sendMessage is not a function I'm puzzled as to why this error occurs, so I've include ...

Navigating with buttons in React JS

In my material-ui, I have a button set up like this: <Button style={green} raised="true" label="Continue to create group"}> CREATE NEW GROUP </Button> I am looking to make it so that when the button is clicked, it will take me ...

Accessing Private Files with Signed URLs from AWS S3

Issue: The challenge is to securely allow users to upload a file and retrieve it later. The files are stored in private Buckets and objects using S3 pre-signed URLs for uploading. However, fetching the file poses a problem as the signed URLs expire after ...

Using jQuery to toggle the visibility of a group of radio buttons causes the div to quickly appear and disappear

My code is working perfectly as it shows up when needed and disappears when necessary. The concept behind this form is that the user can check a box, view more required form data related to the checked item, make those fields required, and then uncheck the ...

Creating a JavaScript function that increments or decrements a variable based on keyboard input is a useful feature

My goal is to have a count start at 100 and then either count up or down by 1 when a specific keyboard button is pressed. Currently, I am using the keys 8 and 2 on the keypad, which represent ascii numbers 104 and 98. So far, the code I have only allows f ...

What are the reasons for deprecating bindToController in Typescript?

When I am creating an AngularJS directive using TypeScript, I typically use the bindToController property to bind parameters to the controller for easy access. export class MyDirective implements IDirective { controller = MyController; controllerA ...

On smaller screens, the top placement of right sidebar links is necessary

Our website layout is organized into 3 main sections: the top part contains the main menu, followed by the main content and a sidebar specific to each page. The main content and sidebar are structured using bootstrap col-* classes. On small screens, I en ...

What's the best way to update the value of an angular field upon submission?

Could someone please provide instructions on how to update the myName variable when the "submit" button is pressed? Thank you! app.js: app.controller('SomeController', ['$scope', 'emails', function($scope, emails) { emails ...

Reloading the table columns in a JSP page with a click of the refresh button on every row using AJAX and JavaScript

Hey there! I have a JSP page with a table where data is displayed by iterating through a list from the action class. Each row in the table has a refresh button at row level. Here is a snippet of the JSP: <script type="text/javascript"> functi ...

Check out the display of the angular array on a PHP webpage

When attempting to display PHP errors in an array to Angular, I encountered the following code: $http.post('includes/functions/functions.php',$.param(values)) .success(function(d){ $scope.error = (angular.isOb ...