簡體   English   中英

如何在Angular中將值從一頁傳遞到另一頁?

[英]How to pass the value from one page to another in Angular?

我有3個鏈接,當我單擊任何鏈接時,我會移至其他頁面:

this.nav.setPages([this.nav.first(), NextPage]);

如何根據單擊的鏈接將值從一頁傳遞到另一頁?

您必須在構造函數中注入Router:

constructor(public router: Router) {}

在要觸發導航的功能中,可以使用:

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

比在NextCmp中您將注入:

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

柱塞: https ://plnkr.co/edit/y3xa2SCGpGlCu4HxhNY8 p = preview

您必須更改功能代碼:

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

以及要在何處使用此參數值注入RouteParams:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM