【发布时间】:2016-01-14 03:49:47
【问题描述】:
我已经阅读了很多关于如何在 modal Bootstrap 中捕获错误的问题,但没有一个可以解释在这种情况下来自 modal 的返回值。
此代码调用模态:
var modalInstance = $modal.open({
animation: true,
templateUrl: 'dummy/test',
controller: 'modalController',
size: 'lg',
}).result.then(function (result) {
$scope.numAttachs = result;
}, function (error) {
// return value???
});
在 modalController 中:
/*... Some logic ...*/
// Button returns values.
$scope.saveValues = function () {
$scope.$close($scope.numAttachs); // This works fine
}
// Event triggered when modal controller destroy
$scope.$on("$destroy", function () {
//$scope.$close($scope.numAttachs); // nope...
// Here I would return value
});
我的目的是在所有情况下都返回变量 numAttachs:
- 用户按下保存按钮。 (我明白了)
- 用户在背景中按下。 (我不明白)
- 用户按下 esc 键。 (我不明白)
我不喜欢在解决方案中暗示事件“$destroy”,这是一种绝望的措施。我想有任何方法可以捕获错误并获得返回值,但我找不到它。 当我在 function (error) { // return value ?} variable error 中捕获错误时,会采用“escape key press”或“backdrop click”的值,但没有办法返回值。有什么建议吗?
感谢您的宝贵时间!
【问题讨论】:
标签: angularjs angular-ui-bootstrap bootstrap-modal