‘router-outlet’ is not a known element
Try this: Import RouterModule into your app.module.ts import { RouterModule } from ‘@angular/router’; Add RouterModule into your imports [] like this: imports: [ RouterModule, ]
Try this: Import RouterModule into your app.module.ts import { RouterModule } from ‘@angular/router’; Add RouterModule into your imports [] like this: imports: [ RouterModule, ]
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
You can achieve what you want with a trick using the resolve option of a route. Resolve is some data value that Angular2 will obtain for the route to be initialized. More details you can find here in the official documentation. I have tried this approach and it does work. Example: Add this to the … Read more
You can use this-> window.location.href=”https://stackoverflow.com/questions/34338440/…”; This would change the page to whatever you want..
The new V3 router has a url property. this.router.url === ‘/login’
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
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
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
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
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