在我的ui-bootstrap模态控制器中,我监视变量。它看起来是这样的:在模式上定义的调用函数在ui-bootstrap模态关闭中
main.controller('modalCtrl', ['$scope', '$rootScope', '$modalInstance',
function ($scope, $rootScope, $modalInstance) {
var unregister = $rootScope.$watch(function() { return $rootScope.someVariable; },
function (newVal) {
if (newVal == false) {
$scope.closeModal();
}
});
$scope.closeModal = function() {
unregister();
$modalInstance.dismiss('cancel');
};
}]);
当我解雇模式我想注销$看,当我做到这一点的NG-点击=“closeModal()”中的HTML它工作正常。但是当我在ESC模式之外点击模式时,它不起作用。那么有没有办法在解雇时调用我的取消注册功能。我知道modal.result.then(close(),dismiss());但如果没有必要,我不想把这个func放到parent $ scope中。
非常感谢。我不知道$ modalInstance具有结果保证。我认为结果承诺只在父范围的模态变量上。 – user3506697
'$ modalInstance'是'$ modal.open'返回的内容。 – dfsq