angular.js - How to get the URL of the current address bar in angular 2
世界只因有你2017-05-15 17:09:22
0
7
883
The URL automatically jumps in the background. How does ng2 get the URL in the address bar and the parameters in it? The answer found online is ng1, and the method is let aid=$location.search().aid;. But $location cannot be found in ng2.
Let’s talk about getting parameters, import {ActivatedRoute} from '@angular/router'; Officially, you have to use rxjs, but it’s okay to force it like this: this._activatedRoute.params'value'
window.location.href
It seems that ng2 method is not needed
angular 2 It’s impossible not to have $location
Angular obtains and modifies the current page URL by injecting $location
window.location.href //URL of the current address bar
this.sub = this.route.params.subscribe(params => {
Official example: Location,
I also encountered this problem, I really can’t find it, please help me
https://angular.io/docs/ts/la...
Let’s talk about getting parameters,
import {ActivatedRoute} from '@angular/router';
Officially, you have to use rxjs, but it’s okay to force it like this:
this._activatedRoute.params'value'