我正在尝试用角度2创建一个应用程序,并且想要传递params来标记[routerLink]中的一个,我想要像这样的链接:
<a href="/auth/signup?cell=1654654654"></a>
我不知道如何在模板中传递细胞…
解决方法
如果你打算使用angula2 beta,那么你必须在做路由时发送这样的参数.
<a [routerLink]="['signup',{cell:cellValue}]">Routing with parameter</a>
<input type='text' [(ngModel)]='cellValue'>
而且在接收方面比你必须通过使用RouteParams得到参数.
如果您要使用angular2 RC而不是必须使用RouteSegment而不是在angular2 RC中使用RouteParams.像这样 :-
import { Component } from '@angular/core';
import { Routes,RouteSegment,ROUTER_DIRECTIVES } from '@angular/router';
@Component({
selector: 'about-item',template: `<h3>About Item Id: {{id}}</h3>`,Directives: [ROUTER_DIRECTIVES]
})
class AboutItemComponent {
id: any;
constructor(routeSegment: RouteSegment) {
this.id = routeSegment.getParam('id');
}
}
@Component({
selector: 'app-about',template: `
<h2>About</h2>
<a [routerLink]="['/about/item',1]">Item 1</a>
<a [routerLink]="['/about/item',2]">Item 2</a>
<div class="inner-outlet">
<router-outlet></router-outlet>
</div>
`,directives: [ROUTER_DIRECTIVES]
})
@Routes([
{ path: '/item/:id',component: AboutItemComponent }
])
export class AboutComponent { }