$ watch returns a function. if you call it, you remove your observer
angular docs , scroll down to $ watch and look at the return value
var myWatcher = $scope.$watch('data', function(after, before) { $scope.saveData(); }, true); myWatcher();
EDIT : with angular -ui-bootstrap you can pass the deregistration function to the modal controller. modified example from docs :
var modalInstance = $modal.open({ templateUrl: 'myModalContent.html', controller: ModalInstanceCtrl, size: size, resolve: { items: function () { return { data: data myWatcher: myWatcher
but I donβt know a simple method (function call or similar) to re-enable the observer. You will have to install it again.
modalInstance.result.then(function (data) { $scope.data = data; }, function () {
nilsK source share