Angular 2 router event listener

new router constructor(router:Router) { router.events.subscribe(event:Event => { if(event instanceof NavigationStart) { } // NavigationEnd // NavigationCancel // NavigationError // RoutesRecognized }); } old Inject the Router and subscribe to route change events import {Router} from ‘angular2/router’; class MyComponent { constructor(router:Router) { router.subscribe(…) } } NOTE For the new router, don’t forget to import NavigationStart from … Read more

Warn user of unsaved changes before leaving page

To also cover guards against browser refreshes, closing the window, etc. (see @ChristopheVidal’s comment to Günter’s answer for details on the issue), I have found it helpful to add the @HostListener decorator to your class’s canDeactivate implementation to listen for the beforeunload window event. When configured correctly, this will guard against both in-app and external … Read more

Angular2 multiple router-outlet in the same template

yes you can, but you need to use aux routing. you will need to give a name to your router-outlet: <router-outlet name=”auxPathName”></router-outlet> and setup your route config: @RouteConfig([ {path:”https://stackoverflow.com/”, name: ‘RetularPath’, component: OneComponent, useAsDefault: true}, {aux:’/auxRoute’, name: ‘AuxPath’, component: SecondComponent} ]) Check out this example, and also this video. Update for RC.5 Aux routes has … Read more

Show loading screen when navigating between routes in Angular 2

The current Angular Router provides Navigation Events. You can subscribe to these and make UI changes accordingly. Remember to count in other Events such as NavigationCancel and NavigationError to stop your spinner in case router transitions fail. app.component.ts – your root component … import { Router, // import as RouterEvent to avoid confusion with the … Read more

Angular: Cannot find a differ supporting object ‘[object Object]’

I think that the object you received in your response payload isn’t an array. Perhaps the array you want to iterate is contained into an attribute. You should check the structure of the received data… You could try something like that: getusers() { this.http.get(`https://api.github.com/search/users?q=${this.input1.value}`) .map(response => response.json().items) // <—— .subscribe( data => this.users = data, … Read more

How to go back last page

Actually you can take advantage of the built-in Location service, which owns a “Back” API. Here (in TypeScript): import {Component} from ‘@angular/core’; import {Location} from ‘@angular/common’; @Component({ // component’s declarations here }) class SomeComponent { constructor(private _location: Location) {} backClicked() { this._location.back(); } } Edit: As mentioned by @charith.arumapperuma Location should be imported from @angular/common … Read more