登录后更改模板

时间:2015-07-23 18:29:03

标签: angularjs authentication firebase

我正在尝试在身份验证后更改页面,但除非我再次单击登录按钮,否则没有任何反应。

以下是代码:

myApp.controller('AuthController', ['$scope','$location', function($scope,$location) {
    // (1)    $location.path('/produtos');
    $scope.email = '';
    $scope.pass = '';

    $scope.submit = function() {
        var ref = new Firebase("https://myfirebasedb.firebaseio.com/");

        ref.authWithPassword({
            email    : $scope.email,
            password : $scope.pass
        }, function(error, authData) {
            if (error) {
                console.log("Login failed !", error);
            } else {
                console.log("Login ok ! "); // (2)
                $location.path('/produtos');
            }
        });
    };
}]);

以下是观察结果 -

  1. (1)的评论说明正常
  2. (2)处的消息在控制台上正确打印
  3. 提前谢谢。

1 个答案:

答案 0 :(得分:0)

看起来有些东西会中断位置变化。试试setTimeout(function(){$location.path('/produtos');}, 0); - 在这种情况下有所帮助。

相关问题