| 
									
										
										
										
											2016-06-09 13:00:26 -05:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-07-16 17:34:26 -05:00
										 |  |  | import { Injectable }    from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-06-09 13:00:26 -05:00
										 |  |  | import { CanDeactivate } from '@angular/router'; | 
					
						
							|  |  |  | import { Observable }    from 'rxjs/Observable'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export interface CanComponentDeactivate { | 
					
						
							|  |  |  |  canDeactivate: () => boolean | Observable<boolean>; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 17:34:26 -05:00
										 |  |  | @Injectable() | 
					
						
							| 
									
										
										
										
											2016-06-09 13:00:26 -05:00
										 |  |  | export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> { | 
					
						
							|  |  |  |   canDeactivate(component: CanComponentDeactivate): Observable<boolean> | boolean { | 
					
						
							|  |  |  |     return component.canDeactivate ? component.canDeactivate() : true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |