1

我正在使用 angular.js 和 AngularFire 并使用他们的聊天示例。重点是用户登录,然后我应该设置var trueRefnew Firebase("https://alfapixteste.firebaseio.com/users/" + $scope.user.ie)这样当用户推送消息时,他们会去他自己的桌子......

user.id问题是当我声明时我无法得到var truerefalert()用户提交消息时工作正常

这是我的完整代码如您所见,我什至尝试将 $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 返回“未定义”

4

0 回答 0