Encountered problem $injector:unpr Unknown Provider for $cookies in ngCookies

Click here to view the error message

Encountered error $injector:unpr Unknown Provider for $cookies

I included the ngcookies module in my app.js file and am using the $cookie service in my controller. However, I am unable to create a cookie as it throws an error when the cookie service is injected in my controller.

app.js

angular.module('advogeApp', [
'ngResource',
'ngCookies',
'editorCtrl',
'SigninCtrl',
'SignupCtrl']).config(['$routeProvider', function($routeProvider, $httpProvider, $cookies){
    $httpProvider.defaults.xsrfCookieName = 'csrftoken';
    $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);

controller.js

var app = angular.module('advogeApp');
app.controller('SigninCtrl', ['$scope', '$http', '$cookies', '$location', function($scope, $http, $cookies, $location) {$scope.loginData = function () {
            angular.element('#signin').modal("hide");
            $http({
                method : 'POST',
                url : '/proxy/',
                headers: {'Content-Type': 'application/json', 'endpoint' : '/login/'},
                data : JSON.stringify({email : $scope.userEmail, password : $scope.userPwd}),
            }).then(function(response){

                    $cookies.put('set-cookie', response.data.headers['set-cookie']);

                if (response.data.body.info == "sucessfully logged in") {
                            $location.path('/dashboard');
                     } else {
                            $scope.logininfo = response.data.info;
                            console.log(response.data);
                     }
            },function(response){
                console.log(response);
            });

Seeking assistance in resolving this error

Answer №1

It appears that there are some missing injections in the code provided:

file.js

angular.module('exampleApp', [
'ngResource',
'ngCookies',
'someCtrl',
'anotherCtrl']).config(['$routeProvider','$httpProvider', '$cookies', function($routeProvider, $httpProvider, $cookies){
    $httpProvider.defaults.xsrfCookieName = 'csrftoken';
    $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}]);

SUGGESTION (you may want to try this)

service.js

var app = angular.module('exampleApp', ['ngCookies']);

Could it be causing a module conflict?

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 width of the <ul> element does not properly accommodate the width of the <li> elements during the animation that updates the width of the <li>

I am currently working on implementing a typing animation in React. The li element has an animation that recursively changes its width from 0px to 100%. However, I have noticed that when the width of the li changes, the parent ul does not adjust its width ...

Removing a field from a SubDocument using Mongoose

In my current Mongoose setup, I have the following schema and code implementation: Schema: { ... inv: { type: Object, default: {} }, ... } Version 1 of the Code involves targetData as a Mongoose Document, item as a String ...

What is the process for programmatically aligning two cards side by side using Material UI in React after retrieving data from an API?

I am currently working with data from an API that I need to display in the format of cards, arranged side by side. To achieve this, I have been using an array and passing the data to components programmatically. You can see the output image and my code bel ...

Is there a way to remove this specific element from an inherited hyperlink?

My website can be found at whensayfeed.meteor.com. Each post on the site is enclosed within an <a></a> element. The heart symbol on the right side of each post is intended to be a "like button" that users can click on. However, because it is ...

Bi-weekly Calendar Gathering

I am able to get my events sorted by day with the following code: daysOfWeek: [2], However, I have not been able to find any information in the documentation on how to make it sort fortnightly. Can this be done with fullcalendar? Solution: Just a heads ...

Switched over to AngularJs 1.3, now child elements within ngRepeat no longer have access to the directive's scope

When working with Angular 1.2, the element inside ngRepeat had access to the parent scope's function(isConvoTabActive). However, upon switching to version 1.3, this functionality ceased to work. I have searched through the migration guide but found no ...

JavaScript label value vanishing after postback

When using a datepicker in JavaScript, I encountered an issue where the label resets to the default value after a postback to the server, instead of retaining the user's selected values. Despite my attempts to rearrange the code, the label consistent ...

How to ensure a table in MaterialUI always maintains full width without requiring horizontal scrolling in CSS?

After attempting to allocate each widthPercent value on the TableHeader so they sum up to 100%, I am still experiencing the presence of a scroll bar. I have tried setting fixed widths for each column, but this results in excess space on the right side dep ...

trouble encountered when attempting to integrate typeahead functionality in AngularJS using jQuery

Greetings! I am brand new to using AngularJS and currently exploring the implementation of typeahead functionality. I decided to utilize an existing library by including the following script: <script src="lib/xyz/typeahead.bundle.js"></script> ...

Is there a way to retain the selected item in a dropdown list after reloading the browser, especially when the list is populated based on another selection

Can an option be pre-selected in a select list based on another select list after the browser reloads? It may sound confusing, but I'll try to explain. There are two dropdowns. <select id = "select-class" name="class_id" class="form-control" ...

What is the correct way to interpret the URL of attachments in messages?

I'm trying to create a feature where, when someone sends an image or a link of an image (like with Imgur), the attachment's URL gets logged in a specific channel. I attempted to achieve this using if(message.attachments.length > 0 || message. ...

What is the reason why regular expression strings are not surrounded by quotes in JavaScript?

When using regular expressions, apart from JavaScript, the syntax to find a number in brackets typically involves expressions like "\\[[0-9]+\\]" or r"\[[0-9]+\]". This string is then utilized in functions such as Contains("&b ...

Show the advancement of a process as it runs in a pop-up window

Currently, I am working on revamping a webpage to give it a more modern look. However, I'm encountering some challenges when trying to add simple functionality to a modal window. On the webpage, users upload a file, and upon clicking submit, a shell ...

Retrieve data from nested items using GraphQL query with JavaScript Amplify

Explanation: A Group can consist of multiple Members and one member as the leader: type Group { id: ID! name: String leader: Member @connection members: [Member] @connection(name: "GroupMembers") } The Member data model is defined as: ty ...

Encountered issue retrieving HTML file using ExpressJS and JavaScript

I am new to working with Express.js and I encountered an issue when trying to reload the server. The HTML file displays "Cannot get" error, as shown in this console screenshot: https://i.sstatic.net/itrJA.jpg Here is my server-side code for reference: htt ...

Hiding the div element with 'display: none' causes the disappearance

Whenever I execute this piece of code; document.getElementById("loading").style.display = "none" It unexpectedly hides the div named "myDiv" as well. By setting MyDiv to block, the text appears correctly. However, when loading is set to none, it strange ...

Mastering EmberJS 2.7: The Definitive Guide to Binding the 'disabled' Attribute for Buttons

Here is an official guide explaining how to bind a boolean property to the disabled attribute of an HTML element. However, it references a controller in the process. I have a button that, when clicked, transitions the route (it must be a button and not a ...

Guide on launching a mobile application upon clicking a button in a mobile browser (with the assistance of JavaScript/React) [Utilizing Deep Linking]

My goal is to create a functionality where, on a mobile browser, when the user clicks on a button: If the app is already installed on the user's mobile device, it should open up. If the app is not yet installed, I aim to redirect the user to the appr ...

File reading and processing must be completed before attempting to write to a new file. This is a promise-related stipulation

Feeling completely lost and stuck in a rut. Promises seemed straightforward until I actually tried to implement them. Sharing my basic code here without any promise attempts for simplicity's sake. After taking a few months hiatus from this, I returned ...

Use the asset module instead of the file-loader when adding additional loaders in the chain

My webpack configuration includes the following module for processing SCSS files: { test: /atffonts\.scss$/, use: [ { loader: 'file-loader', options: { name: 'style/[name].css', ...