在 AngularJS 中单击按钮打开一个新选项卡 [英] Open a new tab on button click in AngularJS
本文介绍了在 AngularJS 中单击按钮打开一个新选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button>
openTab = function () {
$http.post('www.google.com');
}
我想要的是在单击openTab"按钮时发布一个要求并在新选项卡中打开响应 html.$http
没有办法做到这一点.我觉得这可能很简单,但我找不到办法.
What I want is post a require and open the response html in a new tab when you click the "openTab" button. There is no method to do this with $http
.
I think this maybe simple, but I can't find a way.
推荐答案
您可以使用 $window 服务在控制器中完成所有这些操作 此处.$window 是全局浏览器对象窗口的包装器.
You can do this all within your controller by using the $window service here. $window is a wrapper around the global browser object window.
要使这项工作按如下方式将 $window 注入您的控制器
To make this work inject $window into you controller as follows
.controller('exampleCtrl', ['$scope', '$window',
function($scope, $window) {
$scope.redirectToGoogle = function(){
$window.open('https://www.google.com', '_blank');
};
}
]);
这在重定向到动态路由时效果很好
this works well when redirecting to dynamic routes
这篇关于在 AngularJS 中单击按钮打开一个新选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文