我有几个模态,2个运行良好,1个在关闭时出现此异常。
(它确实设法关闭了模态,但是angular记录了此异常)。
我仔细观察了一下,$modalInstance
是在close
方法内部定义的,但是openedWindows.get($modalInstance)
返回undefined
。
我怎样才能解决这个问题?
最佳答案
这是v0.10.0中$ modal中的错误。请参阅this github issue,并将在下一版本中修复。
@IvanZh在这里提供了类似问题的答案-Dismiss angular modal on URL change - errors in console
在 Controller 中,执行$ modal.open之后,添加一个finally块,在其中您将modalInstance显式设置为null。上面的问题中提供了用于更改URL更改模式的plunkr。您的应该非常相似。
$scope.modalInstance = $modal.open({
templateUrl: 'add.html',
controller: 'AddCtrl'
});
$scope.modalInstance.result.then(function() {
console.log('Success');
}, function() {
console.log('Cancelled');
})['finally'](function(){
$scope.modalInstance = undefined // <--- This fixes
});