-
Notifications
You must be signed in to change notification settings - Fork 3k
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
$onDestroy controller hook on leaving state #3043
Comments
is it an angular 1.5 component? $onDestroy only works with components, as far as I know. |
Yup, it's Angular 1.5.8 |
ok, I'll need a plunker to replicate. http://bit.ly/UIR-Plunk |
@teyc thanks for the plunker. The plunker doesn't contain any components. A component is created using |
I've added component to the sample, but the behavior is still the same. Incidentally, instructions here don't work. https://ui-router.github.io/guide/ng1/route-to-component |
OK, you defined a component, but never used it. Here, take a look: http://plnkr.co/edit/1sbmr00ZAWvRGkgYzeVd?p=preview
Those instructions require ui-router 1.0. The linked plunker is using 0.3.2 (the latest 'stable' release). Here's the same plunker, updated to 1.0 and route-to-component: http://plnkr.co/edit/YWYuYlO9WUyzz2kc7Yu3?p=preview |
Thank you Chris - works as advertised! 👍 |
Thanks for response @teyc I think I will close this ticket since it seems to work, and no response from original reporter. |
Guys, despite the fact that life-cycle hooks are presented/documented in angularJs 1.5 docs for components/directives only, plain controllers used for state templates should not (IMO) behave much differently (for reference this is what Currently if controller for the template was defined through state definition, What do you think? I find this angularJs issue thread to be related: angular/angular.js#15073 |
I agree with the above. We are still using regular controllers with controllerAs syntax, and having issues that the As far as I am aware, the @christopherthielen can we re-open this issue for discussion? |
Reopened for discussion I'm of the opinion that ui-router shouldn't be in the business of re-implementing the built-in angular lifecycle. There are too many things to possibly get wrong. There are many different versions of angular, and there are differences between component lifecycles between them. That's not something I'd like to commit to maintaining. If anything, I'm leaning towards removing the ui-router manual firing of Perhaps theres a better way to construct the template/controller that would lean on angular itself (instead of mimicing its behavior). Today we use |
Thanks, yes I think it's probably correct that ui-router shouldn't have to fire the lifecycle hooks manually. I didn't realise that After posting here, I've started looking into using components for my routes to see if it would mitigate the problem, but my routes aren't showing anything. Am I correct to assume that functionality is available in 0.3.2 as per #2627 (comment)? Or is this only implemented for 1.0.0? |
@adamreisnz it's implemented in 1.0.0-alpha.1 and later. A simple GitHub tip: look above the comment you found and find the referenced commit Then, you can see what branches the commit is in: Regarding route-to-component, there are two things I should mention:
|
Thanks, I'll look into migrating to 1.0.0 |
Why did it get closed? Using components instead of templates with controllers is not addressing this issue. |
Yep found that one. Quick question re original topic. Since |
If I add I don't want to mimic angular core functionality because it would be a maintenance nightmare (I am not willing to undertake maintenance of code that mimics core angular functionality). We use Your two workaround today are:
.state('foo', {
component: 'someDirective',
resolve: { data: () => 'data' },
});
.state('foo', {
template: '<some-directive data="$resolve.data"></some-directive>',
resolve: { data: () => 'data' },
});
As it stands, I see route-to-component to be the future of angular-ui-router. If anyone can find a way to tie into core angular lifecycle hooks, I'll consider reopening. It must not be a breaking change, however. |
I think I understand the reluctancy to add more hooks and keep maintaining them, but if we could only add the relatively simple and basic Note that I do am keen to migrate to routing to components, but our application is quite large, and it will take some time before such a migration can be completed and fully tested. As such, if we were to be able to do it in steps, it would be a lot easier for us. Having the |
FWIW, I've bitten the bullet and upgraded our app to ui router 1.0.0. This was surprisingly less painful than I had thought it would be, and component routing has now solved the need for the @amalitsky I would recommend upgrading as a path forward, it is not as involved as it may seem at first glance and most of the API is still backwards compatible. |
$onDestroy hook is not called when leaving state, but $scope.$on('$destroy') is working.
The text was updated successfully, but these errors were encountered: