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 Answers1

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.

Tyler Jennings
  • 8,761
  • 2
  • 44
  • 39