我基本上遇到了这个问题,我需要引用当前路径来使用渐变,但还没有弄清楚如何将解决方案转换为Angular 2.
Gün*_*uer 33
constructor(location:Location) {
console.log(location.prepareExternalUrl(location.path()));
}
Run Code Online (Sandbox Code Playgroud)
https://angular.io/docs/ts/latest/api/common/index/Location-class.html#!#prepareExternalUrl-anchor
window.location 提供更多信息
gud*_*duf 23
你可以使用DOCUMENT注射@angular/common.
import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/common';
@Component({...})
class SomeComponent {
constructor(@Inject(DOCUMENT) document: any) {
console.log(document.location.href);
}
}
Run Code Online (Sandbox Code Playgroud)
Sag*_*gar 14
使用文档中位置对象内的属性以您需要的方式获取路径.让我们看一个例子.
因此对于 https://www.google.com/images
document.location.href 将返回 https://www.google.com/imagesdocument.location.origin 将返回 https://www.google.comdocument.location.protocol 将返回 https:document.location.host 将返回 google.comdocument.location.hostname 将返回 googledocument.location.pathname 将返回 /images| 归档时间: |
|
| 查看次数: |
33394 次 |
| 最近记录: |