gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 00:06:53 24 4
gpt4 key购买 nike

在 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>

skipModalInstance Controller ...

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);

非常感谢您的帮助。

最佳答案

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

关于javascript - 使用 event.preventDefault 单击不触发引导模式按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38177920/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com