Подтвердить что ты не робот

Как перенаправить на внешний URL-адрес

При попытке перенаправления на внешнюю страницу с помощью $window.location.href страница просто обновляется, а не перенаправляется на ожидаемый URL.

4b9b3361

Ответ 1

<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>

Это работает для меня.

Ответ 2

pdmApp.controller('projectionDetailController', [ '$log', 'projectionDetailService', '$filter', '$window', '$location', '$scope', function ($log, pdService, $filter,$window,$location, $scope) { 

$scope.backToPreviousPage = function () { 
  alert("function is working"); //Add this line to your code to confirm your function is called.
$window.location.href = "http://localhost:port/../sample2.aspx";

} 

} //What is this bracket for?


}]); //you are missing this square bracket.

Изменить на

    pdmApp.controller('projectionDetailController', function ($log, $filter,$window,$location, $scope) { 

$scope.backToPreviousPage = function () { 
  alert("function is working"); //Add this line to your code to confirm your function is called.
$window.location.href = "http://localhost:port/../sample2.aspx";

} 




});