Angularjs “如何拦截事件”;在新选项卡中打开链接";在右键单击链接时

Angularjs “如何拦截事件”;在新选项卡中打开链接";在右键单击链接时,angularjs,Angularjs,我有上面的代码。单击事件时,调用viewArticle方法,其中单击计数器递增。由于此处未使用href,因此它的值为空。但是,当用户右键单击链接并选择“在新选项卡中打开链接”时,我不知道如何处理 <a href="" ng-click="viewArticle($index +(currentPage*pageSize))"> <img ng-src="{{suggestion.imageUrl}}" class="widget-cse__content__item-

我有上面的代码。单击事件时,调用viewArticle方法,其中单击计数器递增。由于此处未使用href,因此它的值为空。但是,当用户右键单击链接并选择“在新选项卡中打开链接”时,我不知道如何处理

 <a href="" ng-click="viewArticle($index +(currentPage*pageSize))">
    <img ng-src="{{suggestion.imageUrl}}" class="widget-cse__content__item-title-img"/>

    <div class="widget-cse__content__item-title">{{suggestion.title}}</div>
 </a>
AngularJs方式(伪代码)

添加一个属性以禁用“在新选项卡中打开”并手动设置
$location.path

$('a').click(function(event){
    event.preventDefault();
    window.location = $(this).attr('href');
});

如果要在单击事件时生成
href
,则应使用
ng mousedown
事件,以便可以执行任何事件,如
在新选项卡中打开链接
在新窗口中打开链接
单击

HTML:

element.click(function(event){
    event.preventDefault();
    $location.path = attrs.get('href');
});

您希望右键单击触发viewArticle,还是希望它显示上下文菜单(其中包含“在新选项卡中打开链接”)?我希望右键单击的“在新选项卡中打开链接”的行为类似于单击。Thx。这一次运气好吗?我已经在做了。我想用同样的方法处理Chrome中contextMenu的“在新标签中打开链接”(没有在其他浏览器上测试过)。我的viewArticle代码:$scope.viewArticle=function(index){suggestionService.postView($scope.suggestions[index].assetId)。然后(function(results){$log.info(results);$scope.suggestions[index].counters.views=results.viewCount;});$window.open($scope.suggestions[index.url);}
<a href="javascript:void(0)" ng-mousedown="viewArticle($event, data)">{{label}}</a>
  $scope.viewArticle = function (event, data) {

         // Do your work here
         .......

         // After that set href
         jQuery(event.target).attr('href', 'view/article');


  };