角度模态关闭函数未执行
Angular modal close function not executing
加载模式创建正确,但当finally块被击中时,它并没有关闭它。这有什么已知的原因吗?装载时间很短,但我仍然需要它来处理延迟的情况。我正在用一台设备和Chrome进行测试——只有在Chrome中运行时才会出现问题。
$scope.init = function() {
var dialog = Modals.openLoadingModal();
OfflineManager.getTemplates().then(function(templates) {
$scope.templates = templates.map(function(e) {
// get e
return e;
});
OfflineManager.getInspections().then(function(inspections) {
$scope.inspections = inspections.map(function(e) {
// get e
return e;
});
}).finally(function() {
dialog.close();
});
});
};
模态视图:
<div class="loadingModal">
<data-spinner data-ng-init="config={color:'#fff', lines:8}" data-config="config"></spinner>
</div>
模式服务:
this.openLoadingModal = function(callback) {
var opts = {
backdrop: true,
backdropClick: false,
keyboard: false,
templateUrl: 'views/modals/loading.html'
};
return this.open(opts, callback, null);
};
this.open = function(opts, closeHandler, dismissHandler, model) {
opts.resolve = { modalModel:function() { return model; }};
opts.controller = opts.controller || 'ModalController';
$('div, input, textarea, select, button').attr('tabindex', -1);
var modalInstance = $modal.open(opts);
modalInstance.result.then(function(result) {
$('div, input, textarea, select, button').removeAttr('tabindex');
if (closeHandler) {
closeHandler(result);
}
}, function(result) {
$('div, input, textarea, select, button').removeAttr('tabindex');
if (dismissHandler) {
dismissHandler(result);
}
});
return modalInstance;
};
经过一番搜索,我找到了以下解决方案,该解决方案要等到模态完成打开后才能执行:
.finally(function() {
dialog.opened.then(function() {
dialog.close();
});
});
来源:模式加载angularjs ui bootstrap 后调用函数
根据ui.bootstrap文档-http://angular-ui.github.io/bootstrap/versioned-docs/0.13.3/#/modal
结果-当关闭模态时解决的承诺,而当关闭模态时拒绝的承诺
看起来你试图使用错误的承诺来执行你的逻辑。CCD_ 1作为调用CCD_ 2或CCD_。如果您试图以编程方式关闭模态(而不是在模态模板/控制器中通过ng-click关闭),则需要直接调用$modalInstance.close
或$modalInstance.dismiss
,则将执行result.then
。
相关文章:
- 等待回调函数执行
- 暂停函数执行流程,直到ajax请求完成
- Bigcommerce-是否可以在函数执行后更改文本
- 如何对jquery中的未命名函数执行.call()
- 等待函数执行后再继续
- mootools类型的函数将文本作为函数执行
- 停止从另一个函数执行Javascript函数
- Jquery回调函数执行多次
- 如何使即兴 jquery 暂停当前函数执行
- JavaScript 双函数执行
- 来自函数 Javascript 的 NaN 返回值 ||函数执行顺序
- 如何在 JS 中调用 2 次或更多次时延迟函数执行
- 函数执行的次数超出预期
- JS中函数执行错误
- 为什么这个函数执行了两次
- 从子函数执行父函数;t更新父级'的属性
- 如何在jQuery函数执行's处于活动状态
- 使用javascript函数执行php文件
- jQuery函数执行顺序
- javascript中同步函数执行中的问题