Ignat
Ignat

Reputation: 3787

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

I have 3 links, when I click on any link I move to other page:

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

How to pass the value from one page to another, depending on the link clicked?

Upvotes: 0

Views: 2248

Answers (2)

Vlado Tesanovic
Vlado Tesanovic

Reputation: 6424

You must inject Router in your constructor:

constructor(public router: Router) {}

and in function where you want to trigger nav, you use:

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

than in NextCmp you will inject:

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

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

Upvotes: 1

Nayyar Jamal
Nayyar Jamal

Reputation: 353

you have to change your function code:

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

and where you want to use this param value inject RouteParams:

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

Upvotes: 0

Related Questions