【问题标题】:angular not able to search parameter from the search string角度无法从搜索字符串中搜索参数
【发布时间】:2017-03-08 01:37:01
【问题描述】:

我最近开始使用 Angular 开发一个应用程序。

现在,如果我在主控制器(根 url)中使用 location.search(),它可以完美地工作并给我搜索参数。

localhost:8080/app?foo=bar 完美运行。

但是如果我尝试在任何其他控制器中使用location.search(),它会给我未定义的对象。

localhost:8080/app/exampleroute?foo=bar

我不明白为什么会这样。

我是否缺少任何配置。

我已经启用了 html5 模式。

【问题讨论】:

  • 我很困惑location.search() 没有抛出错误。在我的浏览器上,我得到TypeError: location.search is not a function

标签: javascript angularjs location ngroute


【解决方案1】:

考虑使用专用的 Angular 服务进行 url 解析 https://docs.angularjs.org/guide/$location

【讨论】:

  • 谢谢,我发现如果我在示例路线前面缺少#。所以 localhost:8080/app/exampleroute?foo=bar 完美。但是有什么方法可以在使用 loction.saerch() 时删除 #。
猜你喜欢
  • 1970-01-01
  • 2020-11-16
  • 2020-11-07
  • 1970-01-01
  • 2012-01-24
  • 1970-01-01
  • 1970-01-01
  • 2015-01-24
相关资源
最近更新 更多