-1
    navigationController.$inject = [ '$scope', '$cookies' ];

function navigationController($scope, $state, $http, navbarservice,
        $cookies) {

    function onSignIn(googleUser) {
        var profile = googleUser.getBasicProfile();
        console.log('ID: ' + profile.getId());
        console.log('Name: ' + profile.getName());
        console.log('Image URL: ' + profile.getImageUrl());
        console.log('Email: ' + profile.getEmail());
        console.log('id_token: ' + googleUser.getAuthResponse().id_token);

        $cookies.put("useEmail", profile.getEmail());
        $cookies.put('IdToken', googleUser.getAuthResponse().id_token);
        $cookies.put('userName', 'Shreyas');

        console.log($cookies.get(IdToken));

    }
    window.onSignIn = onSignIn;

i trying to store values in cookies but dont know why iam getting this error and i included cookies.min.js file and added dependencies 'ngCookies' also.

  • Possible duplicate of [Angular and $cookies - $cookies.get is not a function](http://stackoverflow.com/questions/28971126/angular-and-cookies-cookies-get-is-not-a-function) – Ramesh Rajendran Jan 24 '17 at 07:44

2 Answers2

0

TypeError means that value of $cookies is undefined - make sure you are injecting this service properly.

uksz
  • 18,239
  • 30
  • 94
  • 161
0

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

$cookies.key = "data";
var value = $cookies.key; 

Otherwice you need to use $cookieStore

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

Referred from : click here

Community
  • 1
  • 1
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234