【问题标题】:Uncaught TypeError: Cannot read property 'put' of undefined未捕获的类型错误:无法读取未定义的属性“放置”
【发布时间】:2017-06-08 21:50:48
【问题描述】:
    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;

我试图将值存储在 cookie 中,但不知道为什么会收到此错误,我还包含了 cookies.min.js 文件并添加了依赖项“ngCookies”。

【问题讨论】:

标签: angularjs google-signin


【解决方案1】:

TypeError 表示 $cookies 的值未定义 - 请确保您正确地注入此服务。

【讨论】:

  • 我定义正确,因为在某些情况下它工作正常。
【解决方案2】:

如果您使用的是 1.3.x 或以下版本,您可以按如下方式使用 $cookies

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

否则你需要使用$cookieStore

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

引用自:click here

【讨论】:

    猜你喜欢
    • 2018-06-17
    • 2019-01-22
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2015-01-06
    • 2017-07-26
    • 2019-02-26
    相关资源
    最近更新 更多