4 回答
TA贡献1862条经验 获得超6个赞
在Angular8中使用PlatformLocation类,此类保存url链接信息,如基地址,端口号等。使用如下:
constructor(private platformLocation: PlatformLocation) {}
ngOnInit() {
console.log(this.platformLocation.href);//href属性即是当前url
}
TA贡献2036条经验 获得超8个赞
import { Component, OnInit, Inject } from '@angular/core';
import {ActivatedRoute, Params} from '@angular/router';
@Component({
selector: 'demo',
template: `<div></div>`
})
export class DemoComponent implements OnInit {
constructor(@Inject(ActivatedRoute) private router: ActivatedRoute) { }
ngOnInit() {
this.router.params.subscribe((params: Params) => {
// params
});
}
}
TA贡献1803条经验 获得超6个赞
rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
$rootScope.previousState = from;
$rootScope.previousParams = fromParams;
});
TA贡献1848条经验 获得超10个赞
import { Component, OnInit, Inject } from '@angular/core';
import {ActivatedRoute, Params} from '@angular/router';
@Component({
selector: 'demo',
template: `<div></div>`
})
export class DemoComponent implements OnInit {
constructor(@Inject(ActivatedRoute) private router: ActivatedRoute) { }
ngOnInit() {
this.router.params.subscribe((params: Params) => {
// params
});
}
添加回答
举报