简体   繁体   English

通过右键单击从当前或新选项卡中的href调用Angular $ scope.Function?

[英]Call an Angular $scope.Function from href in current or new tab by right click?

I have following HTML: 我有以下HTML:

<a href="" ng-click='redirectToEntity("B-",obj.id")'>Click me and Process function and then redirect</a>

This code does process function and redirect to page which I am targeting, but this does not work for Open in new tab by right clicking . 此代码处理功能,并重定向到我指定页面,但这并不 开放在新标签中 右击 工作 I've tried numerous solution but none worked for me. 我尝试了许多解决方案,但没有一个对我有用。 I need to execute redirectToEntity function only when clicked on "Open in New Tab". 仅在单击“在新选项卡中打开”时,才需要执行redirectToEntity函数。

In order to let the normal right-click menu work, the <a> needs to be a regular anchor tag. 为了使正常的右键单击菜单起作用, <a>必须是常规的定位标记。 So it can't be activated by ng-click . 因此,无法通过ng-click激活它。 If all that redirectToEntity() does is generate a url and redirect from within the controller, maybe instead you should just generate the url and add it to the href like this <a href="{{linkGeneratedInController}}"> . 如果redirectToEntity()所做的只是生成一个URL并从控制器内部进行重定向,则也许您应该只生成该URL并将其添加到href中,例如<a href="{{linkGeneratedInController}}">

Alternatively, you can also use a directive to bind an action to the right click, as is shown here . 或者,您也可以使用指令将操作绑定到右键单击, 如此处所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你如何从href调用AngularJS $ scope.Function? - How do you call an AngularJS $scope.Function from href? 从$ scope.function()内刷新$ scope - Refreshing $scope from inside a $scope.function() Angular中$ scope.Variable和$ scope.Function之间的差异? - Differnce between $scope.Variable and $scope.Function in Angular? Karma测试对scope.function内部函数的调用 - Karma testing a call to a function inside a scope.function 角度$ scope无法正常工作。 试图在控制器$ scope和$ scope.function范围内分配对象值 - Angular $scope not working as expected. Trying to assign object values in a controller $scope and a $scope.function scope AngularJS-在每个$ scope.function调用中重新定义$ scope中的数组 - AngularJS - array in $scope re-defined on each $scope.function call href链接仅在“右键单击新标签”中打开 - href links only open on “right click in new tab” 控制器中定义的函数(javascript)与scope.function(angular函数)的区别 - Difference of function(javascript) vs scope.function(angular function) defined in controller 如何在angular-kendojs中使用href调用有角的$ scope函数 - How to call an angular $scope function using href in angular-kendojs 从新标签页中的当前标签页调用函数 - Calling function from current tab in a new tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM