84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
后台自动跳转的URL,请问ng2怎么获取地址栏的URL,以及其中的参数?网上搜的答案是ng1的,方法是let aid=$location.search().aid;这样的。但是在ng2里找不到$location这个。
window.location.hrefIt seems that ng2 method is not needed
angular 2 It’s impossible not to have $location
//1.获取当前完整的url路径 var absurl = $location.absUrl(); //http://172.16.0.88:8100/#/homePage?id=10&a=100 //2. 获取当前url路径(当前url#后面的内容,包括参数和哈希值): var url = $location.url(); // 结果:/homePage?id=10&a=100
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 => {
let 变量 = +params['参数名']; }); //当前地址参数
Official example: Location,
import {Component} from '@angular/core'; import {Location} from '@angular/common'; @Component({selector: 'app-component'}) class AppCmp { constructor(location: Location) { location.go('/foo'); } }
I also encountered this problem, I really can’t find it, please help me
import { Component, OnInit, Inject } from '@angular/core'; import {ActivatedRoute, Params} from '@angular/router'; @Component({ selector: 'demo', template: `<p></p>` }) export class DemoComponent implements OnInit { constructor(@Inject(ActivatedRoute) private router: ActivatedRoute) { } ngOnInit() { this.router.params.subscribe((params: Params) => { // params }); } }
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'
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'