javascript - 在 angularJS 中使用 $location 获取基本 url

标签 javascript angularjs

我有一个如下所示的网址

http://localhost:8080/test#/users/list

当我使用以下内容时:-

$location.url() gives me -> "users/list"
$location.path() gives me -> "users/list"
$location.absUrl() gives me ->"http://localhost:8080/test#/users/list" the entire url
$location.host() gives me-> "localhost"

有什么方法可以得到:- http://localhost:8080/test#/ 甚至 test#/

我可以获取整个网址并将其拆分为 /,但我试图寻找是否还有其他方法。

最佳答案

代码可以使用:

$window.location.pathname

使用http://localhost:8080/test#/users/list,它返回/test

欲了解更多信息,请参阅

关于javascript - 在 angularJS 中使用 $location 获取基本 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59502903/

相关文章:

javascript - 带有 JQuery 函数的 Django 静态 Javascript 资源

javascript - AngularJS:使用 ng-click 时获取 sibling

javascript - Angular - 动态增加 ng-model 名称

javascript - 根数据 extjs 之外的嵌套 JSON 访问

javascript - 单页网站的客户端模板

javascript - 检查字符串包含 JavaScript 代码还是普通字符串?

javascript - 在 codeigniter php 中每次点击都显示下拉菜单

javascript - AngularJS V1.1 拦截器总是在末尾有 $q.when

javascript - 如何更改 typescript 中的 CSS 类?

javascript - 极限阵列, Angular