Skip to content

Instantly share code, notes, and snippets.

@edbentinck
Created November 13, 2015 19:49
Show Gist options
  • Select an option

  • Save edbentinck/31f5aa2640630a127a7f to your computer and use it in GitHub Desktop.

Select an option

Save edbentinck/31f5aa2640630a127a7f to your computer and use it in GitHub Desktop.

Revisions

  1. @melekes melekes renamed this gist Aug 18, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @melekes melekes created this gist Aug 18, 2014.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    angular.module('saveBeforeExitExample', [])
    .directive("saveBeforeExit", ["notificationService", function(notificationService) {
    "use strict";

    return {
    link: function(scope, element, attrs) {
    window.onbeforeunload = function(){
    if (element.hasClass("ng-dirty")) {
    element.submit();
    }
    };
    scope.$on("$locationChangeStart", function(event, next, current) {
    if (element.hasClass("ng-dirty")) {
    element.submit();
    }
    });
    }
    };
    }]);