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/[email protected]?folder=INBOX
and the result i get is like that:

email: "[email protected]?folder=INBOX"

but i'm expecting that email should equal only [email protected]
where do i have the problem and how can i fix that please ?!

2
  • Does this answer your question? Get current route without parameters Commented May 24, 2020 at 12:23
  • try this.route.paramMap.get('email) Commented May 24, 2020 at 12:23

2 Answers 2

1

Try this

this.email = this.route.snapshot.paramMap.get('email').split("?")[0];
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.