2014-10-01 41 views
1

我正在嘗試允許登錄用戶將他們的Google ID的標題和說明發布到Firebase,但用戶ID在控制檯中給出了未定義的錯誤。用戶ID不會發布到Firebase

只有當表單發佈時調用addIdea()函數時纔會觸發該錯誤。表單元素只是標題和描述的ng模型。

var app = angular.module("fluttrApp", ["firebase"]); 

app.controller("fluttrCtrl", function($scope, $firebase) { 

var ref = new Firebase("[forge].firebaseio.com/ideas"); 

     var auth = new FirebaseSimpleLogin(ref, function(error, user) { 
     if (!user) { 
      auth.login('google', { 
       rememberMe: true 
      }); 
     } 
     else { 
      console.log(user.displayName); 
      console.log(user.uid) 

      $scope.displayName = user.displayName; 
      $scope.uid = user.uid; 

     } 

     }); 

var sync = $firebase(ref); 


$scope.ideas = sync.$asArray(); 


$scope.title = ""; 
$scope.desc = ""; 

$scope.addIdea = function(title, desc, uid) { 

$scope.displayName = user.displayName; 
$scope.uid = user.uid; 

$scope.ideas.$add(
    { 
     "title": title, 
     "desc": desc, 
     "user": uid 
    } 
    ); 
//The user id needs to be pulled and we need to post 
//the idea id generated here to the user branch 
$scope.title = ''; 
$scope.desc = ''; 
} 

}); 

回答

3

目的user未定義,因爲它是從$scope.addIdea() function的範圍。

它只存在於FirebaseSimpleLogin的回調調用中。請參考Monitoring Authentication以供參考。