重定向到angularjs绝对URL [英] redirect to an absolute url in angularjs

查看:542
本文介绍了重定向到angularjs绝对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将用户重定向到angularjs绝对URL。

How to redirect user to an absolute url in angularjs.

例如:
我有一个网页,我目前的网址( http://example.com/submit
一旦用户点击了网页上的一些按钮,他已经被重定向到其他网页,例如(' http://google.com ')

我试图用

$location.absUrl() == 'http://www.google.com'
$location.path('http://www.google.com')
$location.url('http://www.google.com')

但没有任何工程。

But nothing works.

注意:
该rediretion不应该从web服务器发生。它的一个REST API。
诚征客户端来实现(使用angularjs)如果用户是有效用户(认证用户),重定向他到门户)

Note: The rediretion should not occur from the web-server. Its an REST API. Wanted to achieve in client side(using angularjs) if the user is valid user(authenticated user), redirected him to portal)

感谢

推荐答案

您需要使用浏览器级别的API,对象窗口,也可以注入<在您的控制器code> $窗口引用。

You need to use the browser level API, with the object window, or you can inject the $window reference in your controller.


  • window.location.href =htt​​p://www.google.com;

  • $ window.location.href =htt​​p://www.google.com;

  • window.location.href="http://www.google.com";
  • $window.location.href="http://www.google.com";

参考文献:

窗口

$窗口

最好的解决方案应该在你的 $ routeProvider 配置进行重定向,注射 $窗口对象,并执行所有重定向你所需要的。

Best solution should be perform redirect in your $routeProvider configuration, injecting the $window object and performing all redirection you need.

这篇关于重定向到angularjs绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆