Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: pass a callback to a state when navigating to it #1640

Closed
kvcrawford opened this issue Dec 17, 2014 · 1 comment
Closed

Feature: pass a callback to a state when navigating to it #1640

kvcrawford opened this issue Dec 17, 2014 · 1 comment

Comments

@kvcrawford
Copy link

@kvcrawford kvcrawford commented Dec 17, 2014

Use Case

I have a widgets resource, with a state to create and edit them. This state may be navigated to from multiple contexts, one of which is a campaign-create state. When creating a campaign, the user must either (a) select a widget, or (b) create one. If the user elects to create one, they are navigated to widget-create.

On successful creation, the new widget must be added to a local storage bucket used by campaign-create, and then navigated back to campaign-create. These are very much the concerns of the campaign-create controller, and it would be best implemented there.

If I had callbacks at my disposal, I could do something like this

$state.go('widget-create', {
  success: function(widget) {
    localStorageService.set('widget', widget);
    $state.go('campaign-create');
  }
}
@nateabele
Copy link
Member

@nateabele nateabele commented Dec 20, 2014

Controllers are really intended to be thin layers that bind business objects to UI. If you're trying to compose a specific UI flow, you're better off creating a separate service to handle the navigation that's callable from your controller, and can return a promise that resolves to the selected (or created) widget.

We use promises across the board for async control flow, so introducing callbacks would be a pretty big inconsistency.

@nateabele nateabele closed this Dec 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.