How to Unit Test Angular 2 routing params

Issue Say that I want to simply unit test a component that takes parameters taken from a part of the route. For instance, my component’s ngOnInit looks like this: ngOnInit() { this.route.parent.params.switchMap((params: Params) => this.service.getProject(params[‘projectId’])) .subscribe((project: Project) => this.update(project)); }

Continue reading

How to read data in express js from form data

Issue Here is request payload I can see in console ——WebKitFormBoundaryW5j4rbM04jMUgOkU Content-Disposition: form-data; name="file"; filename="Screenshot from 2016-12-12 18-34-26.png" Content-Type: image/png ——WebKitFormBoundaryW5j4rbM04jMUgOkU Content-Disposition: form-data; name="userId" 12 ——WebKitFormBoundaryW5j4rbM04jMUgOkU Content-Disposition: form-data; name="isAdmin" true ——WebKitFormBoundaryW5j4rbM04jMUgOkU– I need to read userId which is there name="userId"

Continue reading

Angular testing router params breaks test bed

Issue When I provide params to my TestComponent the test bed blows up if the html contains a [routerLink] testbed setup TestBed.configureTestingModule({ imports: [SharedModule.forRoot(), ManagementModule, HttpModule, RouterModule.forRoot([{ path: ”, component: TestComponent }])], declarations: [TestComponent], providers: [ BaseRequestOptions, MockBackend, { provide:

Continue reading

Angular 2 Router Guards order

Issue Angular 2 router guards can be defined in an array. for example: <code> canActivate: [‘CanAlwaysActivateGuard’,’AuthGuard’] </code> following are my questions: what will be the order of execution for both the guards. if i want to execute AuthGuard only if

Continue reading

@ngrx/router-store vs @angular/router

Issue What are the benefits and disadvantages of using @ngrx/router-store instead of @angular/router? Solution Here is a comparison to the now deprecated beta router https://gitter.im/ngrx/store?at=5710e4fc5cd40114649b9399 the main differences between the component router and ngrx/router are the decisions behind the design.

Continue reading

Angular 6 route path not working for direct url when deployed in subdirectory

Issue app.routing.module.ts import { NgModule } from ‘@angular/core’; import { Routes, RouterModule } from ‘@angular/router’; import { HomeComponent } from ‘./public/home/home.component’; const routes: Routes = [ { path: ‘customers’, loadChildren: ‘../app/customers/customers.module#CustomersModule’ }, { path: ‘admin’, loadChildren: ‘../app/admin/admin.module#AdminModule’ }, { path:

Continue reading

How to pass query parameters with a routerLink

Issue I want to pass a query parameter prop=xxx. This didn’t work <a [routerLink]="[‘/somepath’, {queryParams: {prop: ‘xxx’}}]"> Somewhere </a> Solution queryParams queryParams is another input of routerLink where they can be passed like <a [routerLink]=”[‘../’]” [queryParams]=”{prop: ‘xxx’}”>Somewhere</a> fragment <a [routerLink]=”[‘../’]”

Continue reading

Angular 2 router event listener

Issue How to listen state change in Angular 2 router? In Angular 1.x I used this event: $rootScope.$on(‘$stateChangeStart’, function(event,toState,toParams,fromState,fromParams, options){ … }) So, if I use this eventlistener in Angular 2: window.addEventListener(“hashchange”, () => {return console.log(‘ok’)}, false); it isn’t return

Continue reading