Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

warn user before leaving page angular

import { CanDeactivate } from '@angular/router';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';

export interface ComponentCanDeactivate {
  canDeactivate: () => boolean | Observable<boolean>;
}

@Injectable()
export class PendingChangesGuard implements CanDeactivate<ComponentCanDeactivate> {
  canDeactivate(component: ComponentCanDeactivate): boolean | Observable<boolean> {
    // if there are no pending changes, just allow deactivation; else confirm first
    return component.canDeactivate() ?
      true :
      // NOTE: this warning message will only be shown when navigating elsewhere within your angular app;
      // when navigating away from your angular app, the browser will show a generic warning message
      // see http://stackoverflow.com/a/42207299/7307355
      confirm('WARNING: You have unsaved changes. Press Cancel to go back and save these changes, or OK to lose these changes.');
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to enter js in html 
Javascript :: quagga node 
Javascript :: angular routing example 
Javascript :: filter data from database for specific user in js 
Javascript :: moment get end of next moenth 
Javascript :: $(document).ready(function() { $(".more-items").click(function() { $(this).parent().find(".more").slideToggle(); }); }); 
Javascript :: javascript run function forever 
Javascript :: append string in variable using jquery in each loop 
Javascript :: Validate a gregorian date 
Javascript :: no styles are appearing in angular calendar 
Javascript :: js destructuring explained 
Javascript :: js toggle opacity 
Javascript :: connect react native app to local api macos 
Javascript :: javascript play many background music 
Javascript :: if i pass an object to a function is it the same object javascript 
Javascript :: rfc 7230 
Javascript :: how to creat puzzle 15 at jq 
Javascript :: render blaze in react 
Javascript :: scenario.getname() cucumber-js 
Javascript :: fluentmigrator update row where 
Javascript :: javascript farbige konsole in node 
Javascript :: global site tag (gtag.js) - google analytics gatsby 
Javascript :: expect vue test utils compare objects 
Javascript :: straforma in stringa js 
Javascript :: dont starve together 
Javascript :: how to create nav tab with javascript with validation to move to the next tab 
Javascript :: as;dlkfja;slkdjf;lakjsdfjhatl;kndflkjatojn ;kojt;oknbsd;lk 0p9tjdn,mvnklizchflkjt52897sd984235jsdfvhuaiwetr kjhfdoiu twhfoah a 
Javascript :: using the watch method to monitor route updates in vue 
Javascript :: how to access viewmodel in jquery 
Javascript :: different ways to write react file paths 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =