我正在使用以下AngularJS $location进行测试。我不知道这有什么问题。我只想检查重定向是否正常工作:
HTML
<body data-ng-controller="MainCtrl">
Hello {{name}}!
<button ng-click='go()'>Go</button>
</body>
AngularJS代码
var app = angular.module('location', []);
app.controller('MainCtrl', function($scope,$routeParams, $location) {
$scope.name = 'World';
$scope.go = function() {
$location.absUrl() = 'http://www.google.com';
}
});
发布于 2014-01-14 19:42:06
对于外部URL,$location不会帮助您,请改用$window服务:
$window.location.href = 'http://www.google.com';
请注意,您可以使用窗口对象,但这是不好的做法,因为$window是很容易模拟的whereas window is not。
发布于 2014-05-14 03:59:30
如果您想要更改ng-view,则必须使用'#‘
$window.location.href= "#operation";
发布于 2013-09-18 23:04:42
这条线
$location.absUrl() == 'http://www.google.com';
是错误的。首先,==进行比较,您可能要做的是一个赋值,它使用simple =而不是double ==。
而且因为只有absUrl() getter。您可以使用url(),如果您愿意,它可以用作setter或getter。
参考:http://docs.angularjs.org/api/ng.$location
https://stackoverflow.com/questions/18875467
复制相似问题