我基本上遇到了this https://stackoverflow.com/q/19742805问题,我需要引用当前的路线来使用渐变,但尚未弄清楚如何将解决方案转换为 Angular 2。
constructor(location:Location) {
console.log(location.prepareExternalUrl(location.path()));
}
https://angular.io/api/common/Location#prepareexternalurl https://angular.io/api/common/Location#prepareexternalurl
正如文档所说:
标准化外部 URL 路径。如果给定的 URL 不是以以下内容开头
前导斜杠 ('/'),在标准化之前添加一个。添加哈希如果
HashLocationStrategy 正在使用,或者 APP_BASE_HREF(如果
PathLocationStrategy 正在使用。
这意味着您必须显式指定 APP_BASE_HREF 才能在 Angular 5+ 中获取绝对路径。
window.location
提供更多信息
笨蛋的例子 https://plnkr.co/edit/xvwySO0pwRXUn9CUXcJu?p=preview
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)