【发布时间】:2016-03-30 20:42:09
【问题描述】:
有没有办法返回使用 Angular 2 编码的所有段的完整 url 表示?
根据 Angular 1 文档,$location.absUrl();将原样返回。
https://docs.angularjs.org/api/ng/service/$location
方法 absUrl();此方法仅是 getter。
返回完整的 url 表示,所有段编码根据 RFC 3986 中指定的规则。
// given url http://example.com/#/some/path?foo=bar&baz=xoxo var absUrl = $location.absUrl(); // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
【问题讨论】:
-
不幸的是,我能找到的最接近的方法是注入 Location 然后执行:this.location.prepareExternalUrl(this.location.path()),它返回除“example.com”之外的所有内容
-
@RobLouie 是否有在任何地方使用此类代码的示例?我需要完全按照您的要求进行操作,但在导入“位置”的方式和位置方面遇到了问题。
-
我不知道这个确切用例的示例,但在 Angular 2 文档中有一个注入和使用位置的示例:angular.io/docs/js/latest/api/router/Location-class.html。