本文介绍了AngularJs - 在新标签页中打开 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有公共页面和管理页面的应用程序.我想在登录后在新选项卡中打开管理页面.我试过这个,登录成功后,但没有效果.公共页面(登录所在的位置)正在重新加载:

var url = $state.href('/admin/overview');$window.open(url, '_blank');

任何提示将不胜感激.谢谢.

解决方案

这是一个有效的 JSFiddle, 你必须注入 $window 才能使用它:

JS:

angular.module('myApp', []).controller('dummy', ['$scope', '$window', function ($scope, $window) {$scope.redirectToGoogle = 函数 () {$window.open('https://www.google.com', '_blank');};}]);

HTML:

<a ng-href="" ng-click="redirectToGoogle()">你好</a>

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.

解决方案

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>

这篇关于AngularJs - 在新标签页中打开 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 13:55