2016-01-21 165 views

回答

1

您必須在構造函數中注入路由器:

constructor(public router: Router) {} 

,並在要觸發導航功能,您可以使用:

this.router.navigate(['./NextCmp', {param: 3}]) 

比NextCmp你會注入:

constructor(public params: RouteParams) { params.get('param'); } 

Plunker: https://plnkr.co/edit/y3xa2SCGpGlCu4HxhNY8?p=preview

+0

我可以在RouteParams中發送對象/數組嗎? –

+0

不,但你總是可以序列化 - 反序列化它。 –

+0

對象或其他東西的序列化/反序列化?我無法正確地得到你。如果你知道答案,請回答這裏http://stackoverflow.com/q/34432886/5043867 –

0

你必須改變你的函數代碼:

this.router.parent.navigate(['/PreviousDetailsCmp' {value1:abc, value2:xyz}]); 

,並要使用此參數值的方式注入RouteParams:

constructor(public params: RouteParams){ 
     this.val1 = params.get('value1') 
     this.val2 = params.get('value2') 
    } 
相關問題