AngularJs - 在新标签页中打开网址
我有一个带有公共页面和管理页面的应用程序.我想在登录后在新选项卡中打开管理页面.我试过这个,登录成功后,但没有效果.公共页面(登录所在的位置)正在重新加载:
I have an application with a public page and an admin page. I would like open the admin page in a new tab after login. I've tried this, after the login was successful, but to no effect. The public page (where the login is) is just being reloaded:
var url = $state.href('/admin/overview');
$window.open(url, '_blank');
任何提示将不胜感激.谢谢.
Any tips would be appreciated. Thank you.
推荐答案
这是一个工作 JSFiddle,你必须先注入 $window
才能使用它:
Here is a working JSFiddle, you have to inject $window
before you can use it:
JS:
angular.module('myApp', [])
.controller('dummy', ['$scope', '$window', function ($scope, $window) {
$scope.redirectToGoogle = function () {
$window.open('https://www.google.com', '_blank');
};
}]);
HTML:
<div ng-app="myApp" ng-controller="dummy">
<a ng-href="" ng-click="redirectToGoogle()">Hello</a>
</div>
相关文章