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

feat(uiView): Fire the $onInit hook #2570

Merged
merged 1 commit into from
Mar 5, 2016

Conversation

dgsmith2
Copy link

After instantiating the controller, will fire its $onInit if defined.

Closes #2559

After instantiating the controller, will fire its $onInit if defined.

Closes angular-ui#2559
@christopherthielen
Copy link
Contributor

I think this looks good.

A couple observations:

That said, I don't see much of a downside.

I'll be curious if ng-view does something similar.

@dgsmith2
Copy link
Author

This is a bit contrived, but a downside of NOT doing it is you lose the ability to reuse a (component) controller that implements $onInit in all these extra scenarios and more.

I submitted a similar PR to address it with modals: angular-ui/bootstrap#5509. Currently, there are no objections, but your observations may be worth noting over there as well.

@christopherthielen
Copy link
Contributor

lose the ability to reuse a (component) controller that implements $onInit

As I think about it, the whole point of $onInit it to allow the bindToController or bindings to be done after controller constructor is invoked, and then call $onInit in order to use the bound data.
edit: I found out that this is not the case

I don't think $onInit is useful without some sort of bindings (or $ctrl.$resolve) support.

@dgsmith2
Copy link
Author

Are you opposed to an initialization hook in general or one name "$onInit" due to the unmet implications of 1.5 component controllers?

I've found that having a hook at the very least simplifies testing. In situations in which a controller needs to make a request when it is initialized one only needs to mock the service call when testing the hook call.

@christopherthielen
Copy link
Contributor

I'm in favor of the $onInit hook but don't think it's necessary until we support binding to component in some manner.

@petebacondarwin
Copy link
Member

It might be worth noting that the new component router has its own hooks. Notably it calls $routerOnActivate when the component has been instantiated and wired up by the ng-outlet (which is equivalent to your ui-view).

@christopherthielen christopherthielen merged commit c8afc38 into angular-ui:master Mar 5, 2016
christopherthielen added a commit that referenced this pull request Mar 5, 2016
@christopherthielen christopherthielen added this to the 0.2.19 milestone Mar 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants