【问题标题】:AngularJS - Redirect to another domain from codeAngularJS - 从代码重定向到另一个域
【发布时间】:2013-08-23 12:20:34
【问题描述】:

我已经设置了一个 plunker 来描述我的问题:Plnkr

实际上我想导航到另一个域中的另一个页面(添加一个处理程序到按钮单击)。但它不起作用。

提前致谢。

更新

window.location.href = "http://google.com"; 正在工作,但来自 AngularJS 默认的 $location.absUrl 服务不工作。

【问题讨论】:

    标签: javascript redirect angularjs


    【解决方案1】:

    $location 服务不允许重新加载页面。 The Angular way to perform a redirection to another domain is to use the $window service:

    $window.location.href = 'http://google.com'
    

    【讨论】:

      【解决方案2】:

      不幸的是,$location 服务只允许您更改 Web 应用程序的相对路径,无论您想被重定向到另一个您必须使用 window.location.href 的站点

      【讨论】:

        【解决方案3】:

        您没有在 html 上定义 ng-app。而且也没有在 html 上连接你的控制器。在此处查看更新的小提琴

        http://plnkr.co/edit/pPJcWtLrbQOHDT5mXleK?p=preview

        【讨论】:

          猜你喜欢
          • 2013-05-18
          • 2015-08-20
          • 2013-09-02
          • 2019-11-25
          • 2010-10-14
          • 2019-01-12
          • 2013-08-04
          • 2018-07-15
          相关资源
          最近更新 更多