angular2-routing

Why doesn't this route match when navigating to it directly?

折月煮酒 提交于 2019-12-10 03:54:15
问题 For the record: This is using the currently rather new "@angular/router": "3.0.0-alpha.8" , the route definitions are at the bottom of the post. When attempting to navigate in my application the behaviour is different depending on whether I enter the URL directly or following a link: Works: Entering http://localhost:9292 in the address-bar, correctly forwards to http://localhost:9292/about Works: Navigating directly to http://localhost:9292/about via the address-bar Works: If I navigate to

How to reload the component of same URL in Angular 2?

心不动则不痛 提交于 2019-12-10 03:04:55
问题 I am trying to reload the same url in Angular 2 by using router.navigate but it is not working. url : http://localhost:3000/landing Scenario : I am on http://localhost:3000/landing and now I am changing a particular parameter in the page which should reload the page. Code : let link = ['Landing']; this.router.navigate(link); 回答1: Navigate to some dummy component and then navigate to the component that you want to reload. //the second parameter _skipLocationChange=true to avoid that url in

ngOnInit not called when same component is loaded with different data

心已入冬 提交于 2019-12-10 02:22:49
问题 I have an angular 2 app, and I use router to navigate between views, like everyone else. Here is how my path for a particular component look like: { path: 'home/view1/:viewID', component: ViewComponent, children: [ { path: 'pane/:paneId/section/:sectionId', component: SectionEditComponent }, { path: '**', component: ViewEditComponent } ] }, Now, I have two buttons on the ViewComponent, to load SectionEditComponent for section1 and section2. Path1: pane/1/section/1 Path2: pane/1/section/2

How to trigger route resolver manually

旧时模样 提交于 2019-12-10 02:13:56
问题 I'm resolving a user before accessing the account fragment of my user page : app-routing.component.ts { path: 'users/:id', component: UserComponent, resolve: {user: UsersService}, children: [ {path: '', pathMatch: 'full', redirectTo: 'account'}, {path: 'account', component: UserAccountComponent}, {path: 'sites', component: UserSitesComponent} ] } users.service.ts resolve(route: ActivatedRouteSnapshot, r: RouterStateSnapshot) { return this.getUser(route.params['id']); } user-account.component

Angluar2 routing inside http interceptor

一个人想着一个人 提交于 2019-12-10 01:45:40
问题 I use Angular 2.4.8. Communication with backend is via REST. In each request I need to send X-Auth-Token in header. The token is stored on session. When token is outdated server returns 401 status. In such a case I want application to go to login page. I added http interceptor to my project @Injectable() export class HttpInterceptor extends Http { constructor(backend: XHRBackend , defaultOptions: RequestOptions , private router: Router ) { super(backend, defaultOptions); } request(url: string

router-outlet is not a known element

梦想的初衷 提交于 2019-12-10 00:53:27
问题 The following code works: /*app.module.ts*/ import { NgModule } from '@angular/core'; import { HttpModule } from '@angular/http'; import { AppComponent } from './app.component'; import { LetterRecall } from './letterRecall/letterRecall.component'; @NgModule({ imports: [BrowserModule, HttpModule], declarations: [AppComponent, LetterRecall], bootstrap: [AppComponent], }) export class AppModule {} /*app.component.ts*/ import {Component} from '@angular/core'; @Component({ selector: 'my-app',

Angular 2 roles and permissions

筅森魡賤 提交于 2019-12-09 18:38:43
问题 I have used angular2 and laravel 5.3 in my project. in laravel when user logged in server will be send the permissions of the user to handle authorization in angular. so I wrote a guard to protect routes from users that cannot access. here is my guard class code: export class AccessGuard implements CanActivate{ permissions; currentRoute; constructor(private authService:AuthService,private router:Router){ this.permissions = this.authService.getPermissions(); } canActivate(route:

How do you inject an angular2 service into a unit test? (RC3)

六眼飞鱼酱① 提交于 2019-12-09 18:30:14
问题 I am using RC3 . I am implementing the new Angular2 router as documented here: https://angular.io/docs/ts/latest/guide/router.html Everything works fine but I am having problem in unit testing. Specifically, I cannot inject Angular2 services into my unit tests. My relevant component code is: import {Component} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; @Component({ templateUrl: ... styleUrls: ... }) export class Route1DetailComponent { constructor(private route

Angular. Router DI not working when using APP_INITIALIZER

二次信任 提交于 2019-12-09 18:20:46
问题 I'm preloading app configuration from server with APP_INITIALIZER in following way, AppModule : providers: [ ConfigService, { provide: APP_INITIALIZER, useFactory: configServiceFactory, deps: [ConfigService], multi: true } ], Then, ApiService injected manually from ConfigService : @Injectable() export class ConfigService { private api: ApiService; public constructor( private injector: Injector ) { // Avoid cyclid dependencies, inject manually: this.api = injector.get(ApiService); } And

Angular 2, routerOnActivate method is never called for a component that implements OnActivate

馋奶兔 提交于 2019-12-09 17:42:35
问题 I am trying to log the current route using Angular 2 Router, using the sample code from the official documentation: https://angular.io/docs/ts/latest/api/router/OnActivate-interface.html import {Component} from 'angular2/core'; import { OnActivate, ComponentInstruction } from 'angular2/router'; @Component({selector: 'header-title', template: `<div>routerOnActivate: {{log}}</div>`}) export class HeaderTitle implements OnActivate { log: string = ''; routerOnActivate(next: ComponentInstruction,