Angularjs window.location.pathname与$location.$$path(角度)

Angularjs window.location.pathname与$location.$$path(角度),angularjs,Angularjs,我正在评估路由和控制器中的某些逻辑的路径,它看起来像是window.location.pathname可以作为为$location.$$path注入$location的替代方案,但我不确定Angular在使用window.location时是否存在我不知道的问题 使用“window.location.pathname”有什么问题吗?Angular.js是js中的一个框架,因此,这将非常有效,但我向您推荐的原则是,如果您选择一个框架,请在该框架内工作。使用$location并签出$route 我希

我正在评估路由和控制器中的某些逻辑的路径,它看起来像是
window.location.pathname
可以作为为
$location.$$path
注入
$location
的替代方案,但我不确定Angular在使用window.location时是否存在我不知道的问题

使用“window.location.pathname”有什么问题吗?

Angular.js是js中的一个框架,因此,这将非常有效,但我向您推荐的原则是,如果您选择一个框架,请在该框架内工作。使用$location并签出$route


我希望它能有所帮助。

我想你可以读到关于

$location
是一种基于
窗口的角度服务。location
但它有更多的功能和属性可供使用

我什么时候应该使用$location

应用程序需要作出反应的任何时候 更改当前URL,或者如果要更改当前URL 浏览器中的URL


因此,如果您只获取位置,则可以安全地使用
window.location.pathname
因为它是本机Javascript,但每次需要与位置交互时,我建议使用
$location
服务我发现,在控制器中使用
window.location
ui-sref
链接用于在状态之间转换

如果我改用
$location.path()
,url路径会在控制器中正确更新,因此$location显然是使用Angular/ui路由器时的选择。

这就是我在提问时真正想要的区别