Lor*_*ing 11 javascript routing angular-routing angular
我有这个(主要的父母)组件 -
@RouteConfig([
{ path: '/', name: 'ProjectList', component: ProjectListComponent, useAsDefault: true },
{ path: '/new', name: 'ProjectNew', component: ProjectFormComponent },
{ path: '/:id', name: 'ProjectDetail', component: ProjectDetailComponent },
{ path: '/:id/issues/...', name: 'Issue', component: IssueMountComponent },
])
class ProjectMountComponent {
}
Run Code Online (Sandbox Code Playgroud)
然后我有第二个mount组件(主父的子代,下一个组件的父代)
@Component({
template: `
<div><router-outlet></router-outlet></div>
`,
directives: [RouterLink, RouterOutlet]
})
@RouteConfig([
{ path: "/", name: "IssueList", component: IssueListComponent, useAsDefault: true },
])
class IssueMountComponent {
constructor(private _routeParams: RouteParams) {
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我可以毫无问题地访问routeParams(:id).现在,这是我需要:id
来自uri 的值的组件.
@Component({
template: `
<h3>Issue List</h3>
<ul>
<issue-component *ngFor="#issue of issues" [issue]="issue"></issue-component>
</ul>
`,
directives: [IssueComponent],
providers: [IssueService]
})
class IssueListComponent implements OnInit {
issues: Issue[];
constructor(private _issueService: IssueService,
private _routeParams: RouteParams) {}
getIssues() {
let id = this._routeParams.get('id');
console.log(this._routeParams);
this._issueService.getIssues(id).then(issues => this.issues = issues);
}
ngOnInit() {
this.getIssues();
}
}
Run Code Online (Sandbox Code Playgroud)
在此组件中,我无法访问:id
route参数的值.它始终为空.我究竟做错了什么?
这是组件层次结构 -
ProjectMountComponent - > IssueMountComponent - > IssueListComponent
归档时间: |
|
查看次数: |
7759 次 |
最近记录: |