【问题标题】:Redirect on another url without loading view if condition is false in angular js如果角度 js 中的条件为假,则在不加载视图的情况下重定向到另一个 url
【发布时间】:2016-07-06 15:27:56
【问题描述】:

我正在加载一个页面,但页面有一个条件。如果条件为假,我将在另一个 url 上使用 $window.location.href 重定向 url,但在重定向到另一个 url 之前,默认页面视图首先显示,然后重定向另一个看起来不太好的 url。我很困惑该怎么办。请给我任何解决方案。

function get_bookings() {
    $http.post($scope.domailurl + 'api/class/booking.php?action=get_booking', { 'id': urlid }).success(function(data, status) {
        spinnerService.show('booksSpinner');
        if (data.ticket && data.ticket != "") {
            $window.location.href = $scope.domailurl + '#/attendeesprint/' + data.ticket;
        }
    });
}

【问题讨论】:

    标签: javascript angularjs redirect


    【解决方案1】:

    我不是 100% 确定您的意思,但我确实有一些建议可能会有所帮助。

    第一个建议是使用 Angular 提供的 $location 服务。然后,您可以使用以下行,而不必保留 $scope.domailurl 变量。但是,我假设此路径仍在您的应用程序中。这也可以解决您的默认页面显示问题,因为您不再导致整个页面刷新。

    $location.path('/attendeesprint/' + data.ticket);
    

    我的第二个建议是将 spinnerService.show('booksSpinner'); 行移到 $http 调用之前。这将确保您的微调器在异步服务器操作期间显示。

    【讨论】:

    • 我必须完全更改 url 而不是在该视图中分配
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多