【发布时间】:2015-04-01 19:46:36
【问题描述】:
我有一个 Angular 1.3 项目,使用 ng-route。我正在使用 Angular Toastr 进行用户通知。
通知关闭后,我想将用户发送到路径。
使用以下代码,甚至会触发我的函数并显示调试语句,但浏览器无法导航并且没有显示错误。我错过了什么?
$scope.sendUsername = function() {
if ($scope.myForm.$valid) {
toastr.success('We sent an email to (email address)', {
onHidden: function() {
$log.debug('foo');
$location.path('/');
}
});
}
};
【问题讨论】:
-
如果你使用 .url 而不是 .path 是否有效?
-
FWIW,我唯一能去工作的是
window.history.back(); -
我唯一能想到的是,这是因为在 onHidden 回调的角度范围之外使用了 $location。完成 $location.path 后,尝试使用 $scope.$apply() 手动通知 Angular 事情发生了变化。
-
假设 Angular 的 toastr 类似于普通的 toastr,toast.success 函数的第二个参数就是标题。您正在向它传递一个函数。
标签: javascript angularjs toastr angularjs-ng-route