0
votes

in my Angular-App I try to use cookies to store some values. But I keep getting

Error: $injector:unpr Unknown Provider

Unknown provider: $cookiesProvider <- $cookies <- setlistCtrl

In my html-file, I reference angular-cookies:

<script src="Scripts/angular.min.js"></script>
<script src="Scripts/angular-cookies.js"></script>
<script src="app/app.js"></script>
<script src="app/setlist/setlistCtrl.js"></script>

In the app.js, I create the module and reference ngCookies

(function () {
    myModule = angular.module('myAngularApplication', ['ngCookies']);
}());

In the controller in setlistCtrl.js, I inject $cookies

(function () {
    var setlistCtrl = function ($scope, $http, $cookies) {
        var that = this;
        ...


    angular.module('myAngularApplication').controller('setlistCtrl', ["$scope", "$http", "$cookies", setlistCtrl]);
  }

}());

I use Visual Studio 2013 and the AngularJS 1.4.3 packet installed via NuGet.

Any idea, what might be wrong?

Thanks in advance,
Frank

1
Did you check that the angular-cookies version you have lines up with 1.4.3?Mathew Berg
Yap, it's "@license AngularJS v1.4.3" in the angular-cookies.jsAaginor
How embarrassing. Here's my next code line ... angular.module('poModule', []).filter('arrayToList', function () { ... Looks like I redefined/override the module with module('poModule', []) ...Aaginor
Ha ha, so a piece of code we couldn't even see in the question? :) Glad you figured it out!Mathew Berg

1 Answers

0
votes

The problem was not within the code but with one of the next lines.

Instead of using the getter

angular.module('poModule').filter(...

I used the setter

angular.module('poModule', []).filter(...

Copy'n'paste without exactly knowing what you do is quite dangerous, especially when the developement system doesn't protect you from common pitfalls. I got the code from here: Angular JS Display String Array From Json