user1683056
user1683056

Reputation: 149

Angular - changing the state from the markup

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?

Upvotes: 3

Views: 53

Answers (1)

Mike Feltman
Mike Feltman

Reputation: 5176

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.

Upvotes: 3

Related Questions