如何在ui-router中重新加载页面

时间:2016-03-31 04:15:36

标签: angularjs modal-dialog angular-ui-router

我有一个删除按钮,对于用户的确认,我正在使用模态指令。
这是指令代码

app.directive('modal', function() {
    return {
        template: '<div class="modal fade">' + '<div class="modal-dialog">' + '<div class="modal-content">' + '<div class="modal-header">' + '<button type="button" class="close" data-dismiss="modal" aria-hidden="true" ng-click="close()">&times;</button>' + '<h4 class="modal-title">{{ title }}</h4>' + '</div>' + '<div class="modal-body" ng-transclude></div>' + '</div>' + '</div>' + '</div>',
        restrict: 'E',
        transclude: true,
        replace: true,
        scope: true,
        link: function postLink(scope, element, attrs) {
            scope.title = attrs.title;

            scope.$watch(attrs.visible, function(value) {
                if (value == true)
                    $(element).modal('show');
                else
                    $(element).modal('hide');
            });

            $(element).on('shown.bs.modal', function() {
                scope.$apply(function() {
                    scope.$parent[attrs.visible] = true;
                });
            });

            $(element).on('hidden.bs.modal', function() {
                scope.$apply(function() {
                    scope.$parent[attrs.visible] = false;
                });
            });
        }
    };
});

这是控制器代码

 $scope.deletePlace = function(place) {

        if (place._id) {
            var url = '/api/places/' + place._id;
            $http.delete(url, {})
                .then(function(response) {
                    $scope.showModal = false;

                    $state.transitionTo('dashboard.places.list', null, { reload: true, inherit: true, notify: true }); 

                }, function(response) { // fail
                    $scope.errorMessage = true;
                });
        }
    }

在删除模式上单击“确定”按钮后,模式将隐藏,但黑色屏幕保持不变,页面上的按钮或不可点击,直到我手动刷新页面。在确认模式上单击确定按钮后,有没有办法删除黑屏。如果我手动点击刷新,它将工作。我不想手动刷新它。我想让它自动刷新或从其他方式隐藏黑屏。

1 个答案:

答案 0 :(得分:2)

  1. 尝试$state.reload()如果您使用最新版本的ui-router,它应该适用于大多数情况。
  2. 如果这不起作用,请尝试使用$state.go()$state.transitionTo()并使用{reload:true}附加参数路由到同一页面。
  3. 如果这也不起作用,请创建一个自动执行方法来初始化控制器并再次调用该方法。
  4.   

    激活();

    function activate(){
    }