在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');
}
我想要的是发布一个require并在新标签中打开响应html当您单击openTab按钮时。使用 $ 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屋!
查看全文