【问题标题】:Mouse right click and open in new tab does not work in angularjs鼠标右键单击并在新选项卡中打开在 angularjs 中不起作用
【发布时间】:2016-07-08 11:14:42
【问题描述】:

只有在鼠标右键选择在新标签中打开时,我才需要在新标签中打开链接。

<a ng-href="" ng-click="goState(item.state)">

这是我的 javascript 函数。

scope.goState = function (state: any): void {                        
    $state.go(state);
};

它调用函数并在执行单击时转到新页面,但是当我右键单击鼠标并选择新选项卡时这不起作用。

我使用了&lt;a ng-href="goState(item.state)"&gt;&lt;a ng-href="{{ item.state }}"&gt; 然后它在浏览器中显示Cannot GET /app.dashboard where item.state = app.dashboard。

谁能给我一个很好的方法来做到这一点?

【问题讨论】:

    标签: javascript html angularjs


    【解决方案1】:

    如果您使用的是 Angular ui 路由器,请尝试以下操作:

    <a ng-href="{{ href(item.state) }}">
    

    scope.href = function (state: any): void {                        
        $state.href(state);
    };
    

    关于$state.href()的文档

    【讨论】:

    • 它对我不起作用。这是 url 在浏览器 localhost/href(item.state) 中的显示方式,这是浏览器内容无法 GET /href(item.state)
    • @User1 尝试包裹在{{ }}
    • 如果我添加 ng-href="{{ href(item.state) }}" 然后右键单击鼠标时它不会让我选择在新选项卡中打开
    【解决方案2】:

    我终于可以解决我的问题了

    <a ng-href="{{ href(item.state) }}">
    

    【讨论】:

    • 学习标记正确答案。因为这已经是@jcubic提供的答案了
    猜你喜欢
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 2020-01-16
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    相关资源
    最近更新 更多