尝试从绑定到模板类的数据中绑定 routerLink。根据 angular.io 文档,模板语法似乎是正确的。在应用程序和组件级别都尝试过 ROUTER_PROVIDERS 和 ROUTER_BINDINGS (两者仍然是一个谜),但无济于事。我的代码抛出“有帮助的”错误:TypeError: linkParams.reduce is not a function in [[ 'ClassDetail', {id: class._id} ] in ]
模板:
<div class="container" >
<div class="row">
<div class="col-md-4 block" *ngFor="#class of classes | async">
<h2>{{class.title}}</h2>
<p>{{class.description}}</p>
<p><a class="btn btn-default" routerLink="[ 'ClassDetail', {id: class._id} ]" role="button">View details »</a></p>
</div>
</div>
</div>
如果没有 routerLink' 这会很好。
路线配置:
@RouteConfig([
{ path: '/', component: Home, name: 'Index' },
{ path: '/home', component: Home, name: 'Home' },
{ path: '/about', component: AboutComponent, name: 'About' },
{ path: '/classes/:id', component: ClassDetailComponent, name: 'ClassDetail'}
])