Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

angular

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');
  } 
}
like image 329
AngularM Avatar asked Dec 07 '25 07:12

AngularM


1 Answers

RouteSegment no longer exists. You can use ActivatedRoute

import:

import {ActivatedRoute} from "@angular/router";

constructor:

constructor(private _routeParams: ActivatedRoute){}

to get the params:

this._routeParams.params.subscribe(params => {
        this.id = params['id'];
    });
like image 184
Thyagarajan C Avatar answered Dec 10 '25 06:12

Thyagarajan C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!