AngularJs - Open url in new tab(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 - 在新标签页中打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:AngularJs - 在新标签页中打开网址


- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Flexslider 箭头未正确显示 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01