Angular js-Richtlinie, um zu zeigen, Warnung für die zurück-Schaltfläche Ihres Browsers, wenn nicht gespeicherte Daten in form

Ich bin ein Neuling auf angularjs.Gibt es eine Möglichkeit, zu zeigen, Warnung, wenn ein Formular nicht gespeicherten Daten und drücken der zurück-Schaltfläche Ihres Browsers.
Irgendwelche Hinweise, wie dies zu erreichen wäre willkommen.

Update: :

    angular.module('myApp.directives', []).directive('confirmOnExit', function() {
    return {
        link: function($scope, elem, attrs) {


            $scope.$on('$locationChangeStart', function(event, next, current) {

                if ($scope.myForm.$dirty) {
                    if(!confirm("Ahh the form is dirty, do u want to continue?")) {
                        event.preventDefault();
                    }
                }
            });

            window.onbeforeunload = function(){
                alert('me');
                if ($scope.myForm.$dirty) {
                    return "The Form is Dirty.";
                }
            }
        }
    };
});

Aktualisierten code

    angular.module('myApp.directives', []).directive('confirmOnExit', function () {
    return {
        link: function ($scope, elem, attrs, $rootScope) {
            window.onbeforeunload = function () {
                if ($scope.myForm.$dirty) {
                    return " do you want to stay on the page?";
                }
            }

            $rootScope.$watch(function {
                return $location.path();
            },

            function (newValue, oldValue) {
                if (newValue != oldvalue) {
                    //here you can do your tasks
                } else {}
            },
            true);

            $scope.$on('$locationChangeStart', function (event, next, current) {
                if ($scope.myForm.$dirty) {
                    if (!confirm("The form is dirty, do you want to stay on the page?")) {
                        event.preventDefault();
                    }
                }
            });
        }
    };
});

InformationsquelleAutor iJade | 2013-02-15

Schreibe einen Kommentar