Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

How to create unsave change in angularjs using ngdialog.

Eg: currently we are in page1 some fields we are edited. directly we going to page2 or somewhere that time ngdialog need to popup and ask if your move data will be lost. do you want to continue? with options: save&move, cancel and discard&move. if i choose cancel stay same page. if i choose discard&move discard the details what we enter. if i choose save&move save the details and move to corresponding page anyone help me this..

share|improve this question

You could use the onbeforeunload-function from plain JS:

$scope.view = {};

$scope.view.dirty = true;

$scope.$watch('view.dirty', function (oldV, newV) {
    if (newV) {
        window.onbeforeunload = function(){
            return "Did you save your stuff?";
        };
    } else {
        window.onbeforeunload = null;
    }
}
share|improve this answer
    
can u give me runable sample? @Johannes Jander – Suresh B Feb 2 at 12:21
2  
Stackoverflow is not a site where other people do your work. Try to implement the code I gave you and if you still have problems ask back. – Johannes Jander Feb 2 at 12:23
    
at least tell me the process how to do?@Johannes Jander – Suresh B Feb 2 at 12:25
    
Set $scope.view.dirty to false in the first lines of your controller. Then set an ng-change handler on your input fields in the HTML, bound to a function in your controller's $scope. In the function of that handler, set $scope.view.dirty to true. – Johannes Jander Feb 2 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.