我正在使用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事件?
答案 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.
}