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
Asked
Active
Viewed 233 times
0

Midhilaj
- 4,905
- 9
- 45
- 88
-
you want domain name from url ??? – Pranay Rana Jun 01 '18 at 06:56
2 Answers
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
-
How could you delete my comment?? Is it possible to delete someone's comment on StackOverflow, strange !! – Pardeep Jain Jun 01 '18 at 09:39
-
@PardeepJain - you can flag it if you find not appropriate ..and moderator delete if you proven true – Pranay Rana Jun 01 '18 at 09:40
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