2

I am new to Angular2 Development.

I have a requirment where i need to call Angular2 Web site from my ASP.Net Web site. While calling Angular2 website (localhost:4200\index.html), will pass querystring like as below localhost:4200\index.html?UserID=Chandra

Now my Question is.

How to get UserId querystring value into App Component (i.e. BootStrap Compoent) or any other component.

Please help me witht this.

Thanks in Advance.

1 Answer 1

2

The docs are pretty decent on this if you haven't looked at them. The short answer is, to access query parameters from the a component, you'll need to use the ActivatedRoute:

import { ActivatedRoute } from '@angular/router';

....

export class MyComponent {

    constructor(
      private route: ActivatedRoute,
    ) { }

   ngOnInit() {
     this.route.queryParams.subscribe(queryParams =>
       //do something with queryParams['UserID']
     );
   }

}

The router will hold both route params and query params. They are treated separately. Subscribe to the queryParams to access those parameters.

Hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. it worked for me. But without <router-outlet> </router-outlet> statement , its throwing error.

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.