重定向到另一个视角

时间:2015-08-24 01:53:08

标签: angularjs

我使用sweetalert向用户显示消息。我想在显示消息后重定向到另一个视图。

我的甜蜜信息如下:

swal({
 title: "Some",
 text: "Good for you!",
 type: "success",
 confirmButtonColor: "#3bed94",
 confirmButtonText: "Go to other view!!!!",
 closeOnConfirm: true,
 html: true
 }, function (isConfirm) {
    $location.path('/myViewToShow');
   //$window.location.path('/myViewToShow');
});

当用户点击"保存"时会显示此消息。按钮,在警报内他们看到"转到其他视图!!"按钮,但它不会重定向到另一个视图,直到它再次点击按钮"保存"。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我发现了这个功能,它有效......

$scope.changeRoute = function (url, forceReload) {
        $scope = $scope || angular.element(document).scope();
        if (forceReload || $scope.$$phase) { // that's right TWO dollar signs: $$phase
            window.location = url;
        } else {
            $location.path(url);
            $scope.$apply();
        }
    };

正如@charlietfl所说,也许我必须使用$ scope。$ apply()。

相关问题