2016-04-14 49 views
0

我一直在努力合併我的扁平化數據,但是當我擴展我的$ firebaseObject服務時,我有一些非常奇怪的行爲。我使用工廠來返回用戶數據,例如完整的名稱,工作正常。但是當我嘗試添加第二個方法時,我無法訪問此命令。

我廠:

// user factory 
app.factory("User", ["$firebaseObject", "$firebaseRef", 
    function($firebaseObject, $firebaseRef) { 
     // create a new service based on $firebaseObject 
     var User = $firebaseObject.$extend({ 
      // these methods exist on the prototype, so we can access the data using `this` 
      getTeamName: function() { 
       console.log("this: " + this); // Logs: this: [object Object] 
       console.log("full name: " + this.firstName + " " + this.lastName); // Logs: full name: undefined undefined 
       console.log("this.teams: " + this.teams); //Logs: this.teams: undefined 

       var teamKey = this.teams.$value; // TypeError: Cannot read property '$value' of undefined 
       console.log("teamKey: " + teamKey); 

       var teamObj = $firebaseObject($firebaseRef.teams.child(teamKey)); 
       console.log("teamObj.teamName: " + teamObj.teamName); 
      }, 
      getFullName: function() { // Runs just fine 
       return this.firstName + " " + this.lastName; 
      } 
     }); 
     return function(uid) { 
      // create an instance of User (the new operator is required) 
      return new User($firebaseRef.users.child(uid)); 
     } 
    } 
]); 

奇怪的是,getFullName工作得很好,任何sugjestions?

回答

0

看起來getTeamName不返回任何

+0

我沒有找到任何東西錯誤的測試,但是當我更換「的console.log(‘teamObj.teamName:’+ teamObj.teamName);」 'return teamObj.teamName'它給了我相同的錯誤,「這個」仍然沒有解決 –