Angular 路由图和查询字符串

Angular 路由图和查询字符串,angular,angular2-routing,Angular,Angular2 Routing,我需要捕获查询字符串,但是我得到了一个错误。我正在使用的代码很简单,但是在浏览器中我失败了 @Component({ selector: 'body', viewProviders: [ ROUTER_PROVIDERS], directives: [ CORE_DIRECTIVES, ROUTER_DIRECTIVES], template: '<p>the param is {{foo}}</p>' }) export class ap

我需要捕获查询字符串,但是我得到了一个错误。我正在使用的代码很简单,但是在浏览器中我失败了

@Component({
    selector: 'body',
    viewProviders: [ ROUTER_PROVIDERS],
    directives: [ CORE_DIRECTIVES, ROUTER_DIRECTIVES],
    template: '<p>the param is {{foo}}</p>'
})
export class app {
    constructor(params: RouteParams) {
            // http://local.../?myText=Hello    
            this.foo = params.get('myText');
        }
}
@组件({
选择器:'主体',
viewProviders:[路由器\u提供程序],
指令:[核心指令,路由器指令],
模板:“参数是{{foo}

” }) 导出类应用程序{ 构造函数(参数:RouteParams){ // http://local.../?myText=Hello this.foo=params.get('myText'); } }

政府对这类事情不是很清楚。它完全没有,只有一个
null

我认为您必须用
提供程序
替换
查看提供程序
,或者如果您在引导应用程序时提供
路由器提供程序
,效果更好:-

bootstrap(AppComponent, [ROUTER_PROVIDERS]);

可能会对您有所帮助,如果您仍然有任何问题,请使用错误消息更新您的问题,如果您提供任何plunker,请更新您的问题。

在Angular RC1路由器中,您需要使用组件实现接口来获取路由参数:

import { ROUTER_DIRECTIVES, Router, OnActivate, RouteSegment } from '@angular/router';

Component({
    selector: 'body',
    providers: [ ROUTER_PROVIDERS],
    directives: [ CORE_DIRECTIVES, ROUTER_DIRECTIVES],
    template: '<p>the param is {{foo}}</p>'
})
export class app implements OnActivate {
    constructor() { }

    routerOnActivate(currSegment: RouteSegment) {
        this.foo = currSegment.getParam('myText'),
}
从'@angular/ROUTER'导入{ROUTER_指令,ROUTER,OnActivate,RouteSegment};
组成部分({
选择器:'主体',
提供者:[路由器提供者],
指令:[核心指令,路由器指令],
模板:“参数是{{foo}

” }) 导出类应用程序实现OnActivate{ 构造函数(){} 路由激活(当前段:路由段){ this.foo=currSegment.getParam('myText'), }
您使用的是不推荐使用的路由器软件包吗?我没有使用该软件包。我使用的是最后一个软件包,is 2.0.0-rc.1