I've been writing a simple angular directive to show alert when user closes the browser.
angular.module('myApp').directive("areYouSure", ["$window", function ($window) {
return {
restrict: "E",
link: function() {
alert("I am called");
$window.onbeforeunload = function () {
alert("I am called");
return "are you sure?";
};
}
};
}]);
<div ng-app="myApp">
<areYouSure></areYouSure>
Link function is not being called. what am I missing here