0

How to get http get request sending domain in angular2 we are using
let product_id = this.route.snapshot.queryParams["name"];
this code for get get parameters and how to get domain name that the request sending

Midhilaj
  • 4,581
  • 7
  • 37
  • 75

2 Answers2

0

you can do this

import {DOCUMENT} from '@angular/platform-browser';

constructor(@Inject(DOCUMENT) private document) {
    let url = document.location.protocol +'//'+ document.location.hostname + ':my_port' );
}
Pranay Rana
  • 170,430
  • 35
  • 234
  • 261
0

Apart from Document by angular, you can simply get it using window object like this

constructor(private window: Window, private router: Router) {
   let hostname = this.window.location.hostname;
}

if You want to get URL path name you can get using router instance like this -

this.router.url

So you can get a whole domain name with path and params by concatenating the values you required.

Pardeep Jain
  • 78,495
  • 36
  • 155
  • 210