Closed tony8891 closed 10 years ago
Thanks, sorry for the late reply, just trying to catch up after a long vacation.
Thats not really a function of the dialog. I understand what you're trying to do, I think in this instance the object returned by the modal instance is out of scope of the event, also if this is a link it may have left the page already before the promise is returned. The "confirm" that is allowing you to stop navigation is a function of the browser itself and will pause events waiting for a response, the in page dialog doesn't do this since it works as a JS promise.
I think what you want to do is something like this:
<a class="btn btn-default" ng-click="navigate('http://so.me/url')">Go Some Where</a>
then inside your controller:
var _unsavedFlag = true;
$scope.navigate = function(url){
if(_unsavedFlag){
var dlg = dialogs.confirm("Please Confirm","Warning, Leave without saving?");
dlg.result.then(function(){ // yes
$window.location.href = url; // leaves without saving.
},function(){ // no
// do some saving
});
}
};
Of course you'll have to set _unsavedFlag some how when your $scope models change.
Again sorry for the late reply, hopefully you found a solution in the meantime.
Hi,
I really like what you did. Great job !
I was wandering if i can have this:
Just doesn't stop the navigation.
for me this works if (confirm("warning. Leave without saving?")) { $scope.allowNavigate = true; return true; } else { event.preventDefault(); }