0

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

Aaginor
  • 4,516
  • 11
  • 51
  • 75
  • 1
    Did you check that the angular-cookies version you have lines up with 1.4.3? – Mathew Berg Jul 21 '15 at 15:37
  • Yap, it's "@license AngularJS v1.4.3" in the angular-cookies.js – Aaginor Jul 22 '15 at 08:47
  • 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 Jul 22 '15 at 13:44
  • Ha ha, so a piece of code we couldn't even see in the question? :) Glad you figured it out! – Mathew Berg Jul 22 '15 at 14:54

1 Answers1

0

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

Community
  • 1
  • 1
Aaginor
  • 4,516
  • 11
  • 51
  • 75