Sim*_*ich 14 angular2-routing angular
我的解决方案中有一个代码,它获取应用程序的baseHref
constructor( private router: Router) {
let baseHref = this.router._location._baseHref;
Run Code Online (Sandbox Code Playgroud)
你可以通过私有财产看到我得到的东西.有没有其他方法来获得基本网址?又名路由器添加它的部分之前的网址?
我正在使用angular2 rc4
谢谢
Gün*_*uer 32
本Location类有prepareExternalUrl()这需要基本href考虑.
你也可以尝试注射 constructor(@Inject(APP_BASE_HREF) href:string)
如果APP_BASE_HREF没有明确提供它似乎不能再注入.
PlatformLocation 提供有关URL的更多详细信息:
import {PlatformLocation } from '@angular/common';
constructor(platformLocation: PlatformLocation) {
console.log((platformLocation as any).location);
console.log((platformLocation as any).location.href);
console.log((platformLocation as any).location.origin);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21893 次 |
| 最近记录: |