Angular 2/4: How do you reference path parameters in the route data? -


is there way reference path parameters in data of route?

i have generic route looks this: { path: "servicing/:type/:id", component: basecomponent, data: { title: "servicing" } },

i use title property set title @ top of page (and <title> tags). rather have write special code title handling has know pages should prepend type path param, i'd this: { path: "servicing/:type/:id", component: basecomponent, data: { title: <type> + " servicing" } },

you should manipulating menu content within component resides within. router isn't "really" built handle logic outside of routing. said easiest thing update content within menu component upon route change.

you need import router using activatedroute , tapping it's parameters this:

basecomponent.component.ts

import { activatedroute } '@angular/router';  constructor(     private _activatedroute: activatedroute ) {}  ngoninit() {      // subscribe route parameter observable.     this._activatedroute.params.subscribe(         _params => {             this.type = _params['type'];             this.id = _params['id'];         }     ) } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -