javascript 在 AngularJS 中打开一个新窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33222771/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open a new window in AngularJS
提问by elykl33t
I know this is simple and a dumb question but I can't for the life of me make this work for some reason...
我知道这是一个简单而愚蠢的问题,但由于某种原因,我终其一生都无法完成这项工作......
So I have a link (based on a non-angular popup using onclick):
所以我有一个链接(基于使用 onclick 的非角度弹出窗口):
<a href="page.html" ng-click="popitup('page.html')">Page</a>
And a function within the scope:
以及作用域内的一个函数:
$scope.popitup = function(url) {
return $window.open(url, '_blank', 'height=200,width=150');
};
All I want is, when someone clicks the link, open a new window and display page.html. I have tried changing small parts of the link and the function, but I can't get it. I'm sure it's something small I am doing wrong.
我想要的是,当有人点击链接时,打开一个新窗口并显示 page.html。我曾尝试更改链接和功能的一小部分,但我无法理解。我确定这是我做错的小事。
回答by Swapnil Patwa
回答by Mastro
This worked for me.
这对我有用。
html
html
<a data-ng-click="openPrintMode()">
<i class="fa fa-print"></i>
</a>
controller
控制器
$rootScope.openPrintMode = openPrintMode;
function openPrintMode() {
$window.open($location.$$absUrl + "?v=p", "_blank");
}