Angular and $cookies - $cookies.get is not a function

后端 未结 3 1298
独厮守ぢ
独厮守ぢ 2020-12-15 03:20

I\'m trying to use cookies within Angular - here\'s what I\'m trying:



        
相关标签:
3条回答
  • 2020-12-15 03:54

    In Angular 1.3.14 you can just use

    var favoriteCookie = $cookies[user_id];
    

    See the documentaiton here: Angular Cookies

    0 讨论(0)
  • 2020-12-15 03:57

    The syntax you have is for version 1.4.x but you are referencing an older version. If you do not want to update to 1.4.x, you can use $cookieStore instead as follows:

    $cookieStore.put("key", "value"); 
    var value = $cookieStore.get("key");
    

    Alternatively if you are using version 1.3.x or below, you can use $cookies as follows:

    $cookies.key = "value";
    var value = $cookies.key; 
    
    0 讨论(0)
  • 2020-12-15 03:58

    The following method should work.

    var favoriteCookie = $cookies.user_id;
    
    0 讨论(0)
提交回复
热议问题