我一直在努力合并我的扁平化数据,但是当我扩展我的$ 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工作得很好,任何建议?
答案 0 :(得分:0)
看起来getTeamName
没有返回任何内容