Javascript 引导模式按钮不使用event.preventDefault单击触发

Javascript 引导模式按钮不使用event.preventDefault单击触发,javascript,angularjs,angular-ui-bootstrap,Javascript,Angularjs,Angular Ui Bootstrap,在angular代码中,我有一个代码,用于在触发$locationChangeStart时进行验证。我必须调用event.preventDefault()来取消它并显示引导模式。但是,我必须使用模式按钮单击两次才能使每个按钮操作生效。代码如下: $scope.$on('$locationChangeStart', function (event, next, current) { if (skipValidation.skipAllowed($scope.filteredQuestio

在angular代码中,我有一个代码,用于在触发$locationChangeStart时进行验证。我必须调用event.preventDefault()来取消它并显示引导模式。但是,我必须使用模式按钮单击两次才能使每个按钮操作生效。代码如下:

$scope.$on('$locationChangeStart', function (event, next, current) {

    if (skipValidation.skipAllowed($scope.filteredQuestions[0])) {
        //some code here
    }
    else {

        event.preventDefault();

        skipValidation.openModal();
    }
});
openModal()函数

this.openModal = function (size, locationChange) {

    var modalInstance = $uibModal.open({
        animation: true,
        templateUrl: 'skipModalContent.html',
        controller: 'SkipModalInstance',
        size: size,
        resolve: {
        }
    });

    modalInstance.result.then(function () {
        //$log.info('continue');
    }, function () {
    });
};
skipModalContent.html

<script type="text/ng-template" id="skipModalContent.html">
                    <div class="modal-header">
                        <h3 class="modal-title text-warning">Warnung!</h3>
                    </div>
                    <div class="modal-body">
                        Frage ist erforderlich, zu beantworten.
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" type="button" ng-click="continue()">mache trotzdem weiter</button>
                        <button class="btn btn-default" type="button" ng-click="cancel()">schließen</button>
                    </div>
                </script>

非常感谢您的帮助。

我终于找到了问题所在。$locationChangeStart被调用了两次,因此打开了两个模式

您是否尝试过将“event.preventDefault();”放在“skipValidation.openModal();”之后?仍然存在相同的问题
var skipModalInstanceCtrl = function ($scope, $uibModalInstance, $window) {

$scope.continue = function () {
    $uibModalInstance.close();
    $window.skipModal = true;
};

$scope.cancel = function () {
    $uibModalInstance.dismiss('cancel');
    $window.skipModal = false;
};
};
app.controller('SkipModalInstance', skipModalInstanceCtrl);