# AngularJS 外部URLへのリダイレクト

**URL:** https://forum.ficusonline.com/t/angularjs-url/206
**Category:** WEB Design
**Created:** [2018 年 6 月 21 日午前 8:55 UTC](https://forum.ficusonline.com/t/angularjs-url/206 "2018-06-21T08:55:38Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![tk-fuse](https://forum.ficusonline.com/user_avatar/forum.ficusonline.com/tk-fuse/32/255_2.png) [@tk-fuse](https://forum.ficusonline.com/u/tk-fuse)
#### Post date: [2018 年 6 月 21 日午前 8:55 UTC](https://forum.ficusonline.com/t/angularjs-url/206/1 "2018-06-21T08:55:38Z")

</div>

> <https://stackoverflow.com/questions/29130208/how-to-redirect-to-an-external-url>

```
<html ng-app="myApp">
<head>
</head>
<body ng-controller="myCtrl">
    <p> <a href="https://www.google.co.in/"><button>Click me to redirect from template</button></a></p>
    <p ng-click="myFunction()"> <button>Click me to redirect from controller</button></p>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
    var app = angular.module('myApp',[]);
    app.controller('myCtrl',function($window,$scope){
        $scope.myFunction = function(){
        $window.location.href = 'http://www.google.com'; //You should have http here.
        }
    });
</script>
</body>
</html>

```

\<補足\>  
[https://docs.angularjs.org/guide/$location](https://docs.angularjs.org/guide/$location)

**When should I use $location?**  
Any time your application needs to react to a change in the current URL or if you want to change the current URL in the browser.

**What does it not do?**  
It does not cause a full page reload when the browser URL is changed. To reload the page after changing the URL, use the lower-level API, **$window.location.href**.
