Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - changing the state from the markup

Tags:

angularjs

Currently I'm able to change the state from the controller like this:

$scope.goTo = function(state){
  $state.go(state);
}

<li class="list-group-item" ng-click="goTo('main')">HOME</li>

Is there any way to do it straight from the html instead of having to write a controller function?

like image 435
user1683056 Avatar asked Nov 26 '25 22:11

user1683056


1 Answers

Yes, assuming you're using ui-router you'd use hyperlinks with ui-sref specifying the state to go to. Something like:

<li class="list-group-item"><a ui-sref="HOME">HOME</a></li>

All of the various routing providers support something similar.

like image 176
Mike Feltman Avatar answered Nov 28 '25 16:11

Mike Feltman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!