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,905
  • 9
  • 45
  • 88

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
  • 175,020
  • 35
  • 237
  • 263
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
  • 84,110
  • 37
  • 165
  • 215