AngularM AngularM - 6 months ago 24
AngularJS Question

How in angular2 can you get RouteParams for the new @Angular/router - doesnt seem to exist

How in angular2 can you get RouteParams for the new @Angular/router - doesnt seem to exist

This is my current code:

import {Component} from '@angular/core';
import {Router, ROUTER_DIRECTIVES, RouteParams} from '@angular/router';

@Component({
moduleId: module.id,
selector: 'NewJob',
templateUrl: 'newJob.html',
directives: [ROUTER_DIRECTIVES, Footer]
})

export class NewJob {
router: Router;

constructor(_router: Router, _params: RouteParams){
let slug = _params.get('slug');
}
}

Answer

You use the RouteSegment. https://angular.io/docs/ts/latest/api/router/index/RouteSegment-class.html

You would do use getParam(param: string) : string to get the parameter you need.