Trying to use RouteParams to get query string parameters, but I just get an error
Unable to resolve all parameters for "RouteParams" (?). Make sure all parameters are decorated with Inject or have a valid annotation type and that "RouteParams" is decorated with Injectable. angular2 -polyfills.js: 332 Error: cannot read property 'getOptional' undefined .......
Take a look at Plnkr . How can I use RouteParams without warning?
Important files are:
boot.ts :
import {bootstrap} from 'angular2/platform/browser'; import {ROUTER_PROVIDERS, RouteParams} from 'angular2/router'; import {AppComponent} from './app/app.component'; bootstrap(AppComponent, [ROUTER_PROVIDERS, RouteParams]);
and app.component.ts :
import {Component, OnInit} from 'angular2/core'; import {RouteParams} from "angular2/router"; @Component({ selector: 'app', template: ` <p *ngIf="guid">guid gived is: {{guid}}</p> <p *ngIf="!guid">No guid given in query-string in URL</p> ` }) export class AppComponent implements OnInit { guid:string; constructor(private _params: RouteParams) {}
Update:
I have no routes, I just have a default root route (if you can call it a route at all, when I have no other routes ...). But, as Gianluca suggested, I added the following route configuration:
@RouteConfig([ { path: '/:guid', name: 'Home', component: AppComponent, useAsDefault: true }, ])
But I still get the same error ( Plnkr updated) ...
angular routing
EricC
source share