-3

I have difficulties using <a href, so i try to find another workaround. The plan is to use ng-click to invoke an url, and reload the page using that url.

This is my html :

<li class="item" ng-click="go_to()">
    <img src="img/ionic.png">
    <p>Beginners Guide</p>
</li>

Which call :

app.controller("listController", ['$scope', '$location', function ($scope, $location) {
    $scope.go_to = function () {
        alert("a"); //CALLED
        var url = "http://google.com";
        $location.url(url); //NOT LOADED
    }
}]);

The end goal is, i just want my apps to open the url when the <li> is clicked

Thanks a lot for your help

Blaze Tama
  • 10,828
  • 13
  • 69
  • 129

7 Answers7

2

You can use

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

Full code should look like

    app.controller("listController", ['$scope', '$location', '$window', function($scope, $location, $window) {
    $scope.go_to = function() {
        alert("a"); //CALLED
        var url = "http://google.com";
        $window.location.href = url;
    };
}]);
Atish Kumar Dipongkor
  • 10,220
  • 9
  • 49
  • 77
2

One simple way which always worked for me was :

<a href="...">
<li class="item" ng-click="go_to()">
    <img src="img/ionic.png">
    <p>Beginners Guide</p>
</li>
</a>
Maddy
  • 123
  • 4