【问题标题】:nginclude add / to the main urlnginclude 将 / 添加到主 url
【发布时间】:2015-02-08 06:52:01
【问题描述】:

知道为什么会这样吗?

我尝试使用

ng-include="'html_template'"

网址结果 WITH ng-include

http://localhost/app/grid#/leave

URL 结果 WITHOUT ng-include

http://localhost/app/grid#leave  

注意添加了正斜杠“/”。

【问题讨论】:

  • 有人知道吗?
  • 这是个谜。没人知道为什么?
  • 您能否提供一个 JSFiddle,没有足够的上下文来解决这个问题。
  • 您是说使用 ng-include 会导致您的页面从http://localhost/app/grid#leave 重定向到http://localhost/app/grid#/leave?目前还不清楚。
  • @pasine,使用 ng-include 将 '/' 添加到 url 而不是 localhost/app/grid#leave 它变为 localhost/app/grid#/leave

标签: jquery angularjs angularjs-directive angularjs-ng-repeat angularjs-ng-include


【解决方案1】:

其实还有个问题和答案

Preserve traditional anchor behavior with ng-include

总结该答案,ng-include 需要 $anchorScroll,而 $anchorScroll 需要 $location。只要涉及到$location,它就会把普通的hash改成angular has

这是我对您遇到的相同问题的回答,https://stackoverflow.com/a/27529032/454252

基本上 Angular 使用 ng-include 更改 URL,因为涉及 $location 服务,而且绕过的方式有点棘手

【讨论】:

  • 这是一种老套的方式。我已经通过替换哈希做了类似的事情。寻找更优雅的解决方案。
  • @in_visible,如果你想要一个优雅的解决方案,1)你应该问这个问题的解决方案。 2)你应该列出你试图解决的问题。不问它并列出你已经知道的(你可能是 Angular 专家),我不可能知道你想要什么。
猜你喜欢
  • 1970-01-01
  • 2021-07-15
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
  • 2011-12-15
  • 2020-08-02
  • 2015-01-25
相关资源
最近更新 更多