Reputation: 11678
I'm trying to user Angular cookies in my controller but for some reason it is always undefined:
MyApp.controller('ValidationController', ["$cookies", function($cookies) {
debugger; //checking $cookies here return an object
$cookies.put("test","test"); //trying to add value to the cookie here return TypeError: undefined is not a function
alert(JSON.stringify($cookies));
}]);
var MyApp = angular.module("MyApp", [
"ui.router",
"ui.bootstrap",
"oc.lazyLoad",
"ngSanitize",
"ngCookies"
]);
This is the full stack error:
TypeError: undefined is not a function
at new <anonymous> (CookiesController.js:6)
at Object.e [as invoke] (angular.min.js:37)
at $get.z.instance (angular.min.js:76)
at angular.min.js:59
at s (angular.min.js:7)
at v (angular.min.js:59)
at g (angular.min.js:52)
at angular.min.js:51
at angular.min.js:17
at l.$get.l.$eval (angular.min.js:126)
any ideas?
Upvotes: 3
Views: 8151
Reputation: 136124
Seems like $cookies
doesn't have setter in angular 1.3.10 while angular 1.4.0 does provided, Please refer their documents.
You could solve your problem by 2 ways.
angular 1.3.10
then use $cookieStore
object instead of $cookies
1.4.0.beta.6
latest versionHope this could help you, Thanks.
Upvotes: 5