如何在ui-router链接中添加click事件?

时间:2018-05-17 03:12:02

标签: angularjs routing angular-ui-router

我正在使用angularjs和ui-router。如何在此jscode中触发click事件:

<a ng-if="item.external!==true" id="nav-drafts"
   class="standard-menu-item comm-icon-news" draggable="false"
   ui-sref="root.drafts.index" ui-sref-opts="{inherit: false}"
   href="#/drafts">
    <span class="icon sso-file"></span>
    <span class="menu-item-label" ng-bind-html="item.label">Edits</span>
</a>

如何在传递ui-sref属性的锚点内插入click事件?

1 个答案:

答案 0 :(得分:2)

您可以考虑在点击(ng-click)事件处理程序

上手动重定向

<强> HTML

<a ng-if="item.external!==true" id="nav-drafts" 
   class="standard-menu-item comm-icon-news" draggable="false" 
   ng-click="navigate('root.drafts.index', {inherit: false})">
    <span class="icon sso-file"></span>
    <span class="menu-item-label" ng-bind-html="item.label">Edits</span>
</a>

<强>控制器

navigate(stateName, params) {
   //do other stuff before redirecting
   $state.go(stateName, params); //call this for navigating to other state.
}