Closed
Description
We use the master/detail ui pattern in many of our states, and I commonly want to pre-populate the detail side with the first result from the server. The problem is that doing a state.go()
in the onEnter hook results in an infinite loop. Is there a common way to do this?
example plunker: http://plnkr.co/edit/14pumrI7QoDhDD73kJQr?p=preview.
$stateProvider
.state('posts', {
url: "/posts",
templateUrl: "posts-index.html",
controller: "PostsIndexController",
resolve: {
posts: function(Post) {
return Post.all()
}
},
onEnter: function($state, posts) {
if (posts.length > 1) {
$state.go('posts.show', { postId: posts[0].id });
}
}
})
.state('posts.show', {
url: "/:postId",
templateUrl: "posts-show.html",
controller: "PostsShowController",
resolve: {
post: function($stateParams, Post) {
return Post.find($stateParams.postId)
}
}
})
Metadata
Metadata
Assignees
Labels
No labels