我有以下代码:
https://stackblitz.com/github/NickHodges/datademo
我试图在页面上显示路由的数据。
const routes: Routes = [
{
path: 'comp1',
component: Comp1Component,
data: { info: 'Data from Comp1' }
},
{
path: 'comp2',
component: Comp2Component,
data: { info: 'Data from Comp2' }
}
];
我声明了这样一个组件:
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-comp1',
templateUrl: './comp1.component.html',
styles: []
})
export class Comp1Component implements OnInit {
constructor(public route: ActivatedRoute) {}
ngOnInit() {}
}
data
<p>
comp1 works!
</p>
<p>Comp1Data: {{ route.data['info'] }}</p>
/comp1
如何显示
土地上的财产
Route
?