AngularJS / ui-router: $state.go does not work inside ng-click

Viewed 29004

I have a view where I have the following code:

<input type="button" value="New Post" ng-click="$state.go('blog.new-post')">

The goal is to transition to a new state without having to use href. Unfortunately the code above just does not fire.

I also tried to include $state in the controller for this view:

app.controller('blogPostsController', function($scope, $stateParams, $http, $state) ...

But still nothing. transictionTo also does not seem to work.

Anyone has any idea on how to make this work?

EDIT: I could only make it work by assigning:

$scope.$state = $state;

inside my controller. This seems ugly. There is really no other way to access $state without assigning it to scope?

3 Answers
Related