The code for the confirmation dialogue can be written shorter this way:
$scope.$on('$locationChangeStart', function( event ) {
var answer = confirm("Are you sure you want to leave this page?")
if (!answer) {
event.preventDefault();
}
});
More Related Contents:
- Add directives from directive in AngularJS
- Controller not a function, got undefined, while defining controllers globally
- How to set an iframe src attribute from a variable in AngularJS
- Why is `replace` property deprecated in AngularJS directives? [duplicate]
- How to set bootstrap navbar active class with Angular JS?
- How to require a controller in an angularjs directive
- AngularJS communication between directives
- How to make a directive update ng-model on jquery on event?
- AngularJS – Image “onload” event
- Dynamic NG-Controller Name
- Removing # from url in Angularjs while having .run in routes
- What’s the difference/incompatibility between ng-model and ng-value?
- Where to put model data and behaviour? [tl; dr; Use Services]
- Resetting form after submit in Angularjs
- Dynamic form name attribute in Angularjs
- Can an angular directive pass arguments to functions in expressions specified in the directive’s attributes?
- $watch’ing for data changes in an Angular directive
- Limiting number of displayed results when using ngRepeat
- Detect unsaved changes and alert user using angularjs
- angular directive ignore non-numeric input
- How can I listen for a click-and-hold in AngularJS?
- Extending AngularJs Directive
- ng-selected not working in select element
- Stating directive templateUrl relative to root
- Confirmation dialog on ng-click – AngularJS
- How to Unit Test Isolated Scope Directive in AngularJS
- How to create a custom input type?
- Show pop-ups the most elegant way
- Sort or Rearrange Rows of a table in angularjs (drag and drop)
- How to Create simple drag and Drop in angularjs