【发布时间】:2016-05-03 03:40:08
【问题描述】:
我想使用RouteConfig将一个变量从我的AppComponent传递给Coursescomponent,但是route config中的“data”属性只能传递常量参数,它无法识别“this”。有没有办法做到这一点?
如果不是,将变量传递给路由组件的最佳做法是什么?
@Component({
selector: 'app',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES],
})
@RouteConfig([
{ path: '/courses'
, name: 'Courses'
,component: CoursesComponent
,data:{token:this.token}} // this doesn't work -- cannot read property "token" of undefined
])
export class AppComponent {
token:string;
//I would change the token(string) in this component, and I want to pass this to the routed components
}
【问题讨论】:
标签: typescript angular angular2-routing