Angular - RouteParams Angular - RouteParams typescript typescript

Angular - RouteParams


As @EricMartinez mentioned you have to import RouteParams correctly. I was playing with my plunker and was getting the exact same errors.

I realized I was importing from 'angular2/angular2' and needed to import from 'angular2/router'

Here is a plunker that does exactly what you are looking for but with a "cars" component. Plunker


I also got same problem when injecting my DataService & RouteParams and had to use @Inject in constructor. Here is what I did.

import {Component, Inject, View} from 'angular2/angular2';import {RouteParams} from 'angular2/router';@Component({    selector: 'about'})@View({    template: 'This is {{id}} about page {{name}}'})export class AboutComponent{    name: string = "Sandeep";    id: number;    constructor( @Inject(RouteParams) params: RouteParams)    {        this.id = +params.get('id');    }}

Hope it will help you.


It does not have to do with the issue you had, but its worth saying that you will face the same problem when migrating to Angular2 RC3 ou higher. The Route has changed completely, so your Component will fail again throwing the same exception.

In RC3 or above you will need to rewrite your routes WITHOUT names and your component will need to import ActivatedRoute from '@angular/router' in order to read your parameters. See:

constructor(private activatedRoute: ActivatedRoute) {     this.activatedRoute.params.subscribe(params => {            this.categoryUrl = params['categoryUrl'];}