angularjs - Using $cookies in controller generates TypeError: undefined is not a function -


update: issue resolved

turns out not aware ngcookies separate service not part of standard angular.js. bower.json file referencing angular 1.4beta angular-cookies still loading 1.3. changed 1.4beta , working expected.

i using $cookies in controller in angular 1.4 project getting following error when reference $cookies:

typeerror: undefined not function     @ object.<anonymous> (http://localhost:9000/bower_components/angular-cookies/angular-cookies.js:60:16)     @ object.invoke (http://localhost:9000/bower_components/angular/angular.js:4371:17)     @ object.enforcedreturnvalue [as $get] (http://localhost:9000/bower_components/angular/angular.js:4224:37)     @ object.invoke (http://localhost:9000/bower_components/angular/angular.js:4371:17)     @ http://localhost:9000/bower_components/angular/angular.js:4189:37     @ getservice (http://localhost:9000/bower_components/angular/angular.js:4330:39)     @ invoke (http://localhost:9000/bower_components/angular/angular.js:4362:13)     @ object.instantiate (http://localhost:9000/bower_components/angular/angular.js:4379:27)     @ http://localhost:9000/bower_components/angular/angular.js:8668:28     @ link (http://localhost:9000/bower_components/angular-route/angular-route.js:981:26) <div ng-view="" class="ng-scope"> 

my code:

angular.module('supportalapp', [ 'ngcookies', 'nganimate', 'ngresource', 'ngroute', 'ngsanitize', 'ngtouch', 'cfp.hotkeys', 'ngclipboard']); 
angular.module('supportalapp')   .controller('toolsctrl', function($scope, $cookies) {....   }); 

if remove $cookies, no errors rendered. , confirm, have included 'ngcookie' in app

note $cookies api used associative array before angularjs v1.4.0-beta.6, , online documentation (defaulting development snapshot) refers new get/put api. relevant change https://github.com/angular/angular.js/commit/38fbe3ee8370fc449b82d80df07b5c2ed2cd5fbe

with angularjs <= v1.4.0-beta.5, have following choices:

  • use $cookieprovider
  • $cookies["key"] = value
  • $cookies.key = value
  • (upgrade angularjs)

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -