Kir*_*mar 72 redirect angularjs
我正在使用以下AngularJS $位置进行测试.我不知道这有什么问题.只想检查重定向是否有效:
HTML
<body data-ng-controller="MainCtrl">
Hello {{name}}!
<button ng-click='go()'>Go</button>
</body>
Run Code Online (Sandbox Code Playgroud)
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';
}
});
Run Code Online (Sandbox Code Playgroud)
Fer*_*ira 145
$ location不会帮助您使用外部URL,而是使用$ window服务:
$window.location.href = 'http://www.google.com';
Run Code Online (Sandbox Code Playgroud)
请注意,您可以使用窗口对象,但这是不好的做法,因为$ window很容易模拟,而窗口不是.
小智 10
如果你想改变ng-view你将不得不使用'#'
$window.location.href= "#operation";
Run Code Online (Sandbox Code Playgroud)
这条线
$location.absUrl() == 'http://www.google.com';
Run Code Online (Sandbox Code Playgroud)
是错的.首先==做一个比较,你可能要做的是一个赋值,它是简单的=而不是双==.
因为absUrl()只是吸气剂.您可以使用url(),如果需要,可以将其用作setter或getter.
参考:http://docs.angularjs.org/api/ng.$ location
它可能对你有所帮助!
AngularJs代码示例
var app = angular.module('urlApp', []);
app.controller('urlCtrl', function ($scope, $log, $window) {
$scope.ClickMeToRedirect = function () {
var url = "http://" + $window.location.host + "/Account/Login";
$log.log(url);
$window.location.href = url;
};
});
Run Code Online (Sandbox Code Playgroud)
HTML代码示例
<div ng-app="urlApp">
<div ng-controller="urlCtrl">
Redirect to <a href="#" ng-click="ClickMeToRedirect()">Click Me!</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
168889 次 |
最近记录: |