0

i'm using angular
i have this router

{ path: 'inbox/:email',        component: InboxMessagesComponent  },

and i'm trying to get the email parameter using this code

this.email = this.route.snapshot.paramMap.get('email') ;

the url i have : http://localhost:4200/inbox/test@email.com?folder=INBOX
and the result i get is like that:

email: "test@email.com?folder=INBOX"

but i'm expecting that email should equal only test@email.com
where do i have the problem and how can i fix that please ?!

hamza mon
  • 97
  • 1
  • 9

2 Answers2

1

Try this

this.email = this.route.snapshot.paramMap.get('email').split("?")[0];
Shijil Narayanan
  • 1,011
  • 8
  • 21
1

You should consider always using the Observable BehaviourSubject which is the best approach

 this.route.params.subscribe((p) => {
    const email = p['email']||'';
})

This will work each time the params change then email will be refreshed with the actual value.

Bellash
  • 7,560
  • 6
  • 53
  • 86