【问题标题】:Error occured when converting to Json转换为 Json 时发生错误
【发布时间】:2016-07-05 11:41:00
【问题描述】:

我正在研究火力基地,但不幸的是,我遇到了一个问题,当我将 respUser 放入控制台时,它给出了 [object object],然后我尝试输入 JSON.Stringify,它给了我一个类型错误:转换圆形结构到 Json 然后我用 angular.toJson 转换但它没有工作所以请帮助我, 下面是我的代码..

提前致谢

 $scope.logIn = function () {

  firebase.auth().signInWithEmailAndPassword($scope.email, $scope.password).then(function (user) {
    console.log(user);

    $scope.populateUserLocally(user); 
      }).catch(function (error) {
    var errorCode = error.code;
    var errorMessage = error.message;
    console.log(errorMessage);
  });};



  $scope.populateUserLocally = function (respUser) {
  $scope.userDetails = angular.toJson(respUser); console.log("$scope.userDetails");    };

【问题讨论】:

  • 你应该使用respUser.val()
  • 你能提供你的 plunkr

标签: angularjs firebase firebase-authentication


【解决方案1】:

你应该使用“stringify”来创建 JSON 字符串

    $scope.userDetails = JSON.stringify(respUser);

【讨论】:

  • 我试过 JSON.stringify(respUser) 但没有成功。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多