使用using data object Angular传递数据



我想通过在路由中直接传递数据来使用路由传递数据,参见示例更清楚。我试着这样做,以看到所有的可能性从给定的传递。

在我的例子中,我想将变量toto传递给另一个组件

提前感谢。

一个组件

public toto:string = 'pass this data to two component'

routing.module

const routes: Routes = {
{ 
path: 'two',
component: TwoComponent,
data: toto // I have an error here that says cannot find 'toto
}
}

你不需要把数据放在{},因为数据是Routes类型的属性,而是这样做:

{
path: 'two',
component: TwoComponent,
data:  { //pass your data as object}
}

甚至:

{
path: 'two',
component: TwoComponent,
data:  _variable //if you don't need to use object
}

最新更新