【发布时间】:2016-05-26 10:31:45
【问题描述】:
我正在尝试在 angular2 中使用路由器。我使用一个链接重定向到DesignerComponent 并将page._id 作为RouteParams 传递。
该代码在 angular2-beta 中正常工作。
以下是我的代码:
pages.component.ts
import { Component, OnInit ,Input} from '@angular/core';
import {SearchPipe} from './../../shared/pipes/search-pipe.pipe';
import { GlobalObjectsService} from './../../shared/services/global/global-objects.service';
import { Router,Routes , ROUTER_DIRECTIVES, ROUTER_PROVIDERS} from '@angular/router';
import { DesignerComponent } from './../../+designer/designer.component';
@Component({
moduleId: module.id,
selector: 'app-pages',
pipes: [SearchPipe],
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS],
templateUrl: 'pages.component.html',
styleUrls: ['pages.component.css']
})
@Routes([
{path: '/designer', component: DesignerComponent}
])
export class PagesComponent implements OnInit {
@Input() pages:any;
constructor(private router:Router) {
}
ngOnInit() { }
selectPage(page_id:string){
}
}
在我看来,我做了以下事情:
<div [routerLink]="['Designer',{page_id: page._id}]" class="btn btn-xs btn-success" title="Design Page">
<i class="fa fa-eye fa-fw"></i>
</div>
但它向我显示以下错误:
Argument of type '{ path: string; name: string; component: typeof DesignerComponent; }[]' is not assignable to parameter of type 'RouteMetadata[]'
我只想在点击以 page_id 作为参数的链接时重定向到DesignerComponent。
任何输入?
【问题讨论】:
标签: javascript typescript angular angular2-routing