我正在使用angular.js和AngularFire并使用他们的聊天示例。关键是用户登录,然后我应该将var trueRef
设置为new Firebase("https://alfapixteste.firebaseio.com/users/" + $scope.user.ie)
,这样当用户推送消息时,他们会转到他自己的桌子....
问题在于,当我宣布user.id
时,我无法获得var trueref
。当用户提交消息时,alert()
可以正常工作
这是我的完整代码 正如您所看到的,我甚至尝试在函数外部设置$ scope.user.id,它可以正常工作
var app = angular.module("atendapp", ["firebase"]);
function MyController($scope, angularFire, angularFireAuth) {
//Login e Logout
$scope.login = function () {
angularFireAuth.login("facebook");
};
$scope.logout = function () {
angularFireAuth.logout();
};
$scope.$on("angularFireAuth:login", function (evt, user) {
$scope.meuid = user.id
});
var ref = new Firebase("https://alfapixteste.firebaseio.com/");
$scope.messages = [];
var ide = $scope.meuid;
var trueref = new Firebase("https://alfapixteste.firebaseio.com/usuarios/" + ide)
angularFireAuth.initialize(trueref, {
scope: $scope,
name: "user"
});
angularFire(trueref, $scope, "messages");
$scope.addMessage = function (e) {
if (e.keyCode != 13) return;
alert($scope.meuid)
$scope.messages.push({
idusr: $scope.user.id,
from: $scope.user.name,
body: $scope.msg
});
$scope.msg = "";
};
}
哦,trueref返回'undefined'