AngularJs - 在新标签页中打开网址 [英] AngularJs - Open url in new tab

查看:276
本文介绍了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>

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆