【发布时间】:2014-01-16 23:26:08
【问题描述】:
我遇到了另一个问题,因为这现在不起作用:
$rootScope.$on('$firebaseAuth:login', function(){
$location.path('/content');
因为在用户完成身份验证后,他们应该被重定向到 /content(而不是卡在登录页面,登录按钮由于 ng-hide 而消失(见上文)),但我尝试 $location 并不重要。 path('/content') 不起作用。
我试过了:
waitForAuth.then(function(){
console.log('test');
$location.path('/content');
})
但是 console.log 在用户通过身份验证之前以控制台方式打印出“test”,所以 waitForAuth 似乎也不起作用:/。不知何故,waitForAuth 会触发 console.log,但不会触发 $location.path... 奇怪。
我什至尝试过这样做(使用 waitForAuth 和 $rootScope.$on:
waitForAuth.then(function(){
console.log('test');
$location.path('/content');
$scope.$apply();
})
但我只是得到一个错误,角度 $digest 已经在进行中。
但是,如果我这样做:
app.controller('controller',['$scope','$firebaseAuth','$location','$rootScope',function($scope, $firebaseAuth,$location,$rootScope) {
$scope.$on('$locationChangeStart', function(event) {
event.preventDefault();
});
var ref = new Firebase('https://mybase.firebaseio.com/');
$scope.auth = $firebaseAuth(ref);
$rootScope.$on('$firebaseAuth:login', function(){
console.log("root scope");
$scope.$apply(function(){
console.log("scope");
$location.path('/content');
});
});
}]);
控制台两次注销“root scope”和“scope”,时机恰到好处:只有在用户完成身份验证后,但 $location.path() 仍然不起作用并且用户卡在登录页面/视图。
这也不行:
$rootScope.$on('$firebaseAuth:login', function(){
console.log("root scope");
$scope.$apply(function(){
console.log("scope");
$location.path('/content');
$location.replace();
});
我需要一些帮助:)
【问题讨论】:
标签: angularjs angularjs-scope firebase angularfire