In my ui-bootstrap modal controller I $watch variable. It looks something like this:
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');
};
}]);
When i dismiss modal I want to unregister $watch and when I do that on ng-click="closeModal()" in HTML it works fine. But when I dismiss modal on ESC on click outside of modal it isn't working. So is there any way to call my unregister function on dismiss. I know for modal.result.then(close(),dismiss()); but if it's not necessary I don't want to put that func into parent $scope.