Is there any functional difference between ui-sref
and $state.go()
?
ui-sref
is used in <a>...</a>
and $state.go('someState')
is used in a controller.
In HTML, I would use:
<a ui-sref="currentState.state1">Link</a>
whereas in a function I would use something like:
if(someCondition) {
$state.go('currentState.state1');
}
So, is that it or do I need to add something after $state.go()
? Assuming current state is currentState
.
Yes, there is a difference. As you can see in the question:
Ionic framework $state.go('app.home'); is adding back button on page where i want to go (how to remove it)?
the $state.go by default adds a back button. The solution to make it behave exactly the same way is to call:
before calling $state.go.
There is no functional difference between
ui-sref
and$state.go
. See the docActivating a state
So, these are at the end doing the same, and as we can see in the code of the
ui-sref
directive:it does call
$state.go()
And also as discussed here: ui-sref: