ui-sref和$ state.go()之间有什么功能差异吗?
ui-sref用于< a> …< / a>和$ state.go(‘someState’)在控制器中使用。
在HTML中,我将使用:
<a ui-sref="currentState.state1">Link</a>
而在函数中,我将使用类似:
if(someCondition) { $state.go('currentState.state1'); }
那么,是否需要在$ state.go()之后添加一些东西?假设当前状态是currentState。
ui-sref和$ state.go之间没有功能差异。请参阅文档
原文链接:https://www.f2er.com/angularjs/145375.htmlThere are three main ways to activate a state:
- Call
$state.go()
. High-level convenience method.- Click a link containing the
ui-sref
directive.- Navigate to the
url
associated with the state.
所以,这些都是在结束做同样的,我们可以看到在ui-sref
directive的代码:
... element.bind("click",function(e) { var button = e.which || e.button; if ( !(button > 1 || e.ctrlKey || e.MetaKey || e.shiftKey || element.attr('target')) ) { var transition = $timeout(function() { // HERE we call $state.go inside of ui-sref $state.go(ref.state,params,options); });
它确实调用$ state.go()
也如这里讨论的:ui-sref:
ui-sref='stateName'
– Navigate to state,no params. ‘stateName’ can be any valid absolute or relative state,following the same Syntax rules as$state.go()