简体   繁体   中英

AngularJS - Redirect to another domain from code

I've set up one plunker to describe my problem: Plnkr

Actually I want to navigate to another page in another domain (added one handler to a button click). But it's not working.

Thanks in advance.

Update

window.location.href = "http://google.com"; is working but $location.absUrl service from AngularJS default is not working.

The $location service does not allow to reload the page. The Angular way to perform a redirection to another domain is to use the $window service :

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

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

You not not defined ng-app on you html. And also not wired up your controller on html. See updated fiddle here

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM