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: expose $animate promise to controller #2562

Closed
christopherthielen opened this issue Feb 17, 2016 · 2 comments
Closed

Feature: expose $animate promise to controller #2562

christopherthielen opened this issue Feb 17, 2016 · 2 comments

Comments

@christopherthielen
Copy link
Contributor

This is in relation to #1643

Prior to 0.2.16, a ui-view's $scope was destroyed just before the ui-view started to be animated out. This caused some problems for certain users, because they were relying on the $destroy event to clean up resources (the ticket in question was cleaning up highcharts). They requested that the destroy event be deferred until after the animation was completed.

We misinterpreted the information to mean that any bound variables were becoming unbound, and "garbling" the data on the page while the transition was in progress. This interpretation was incorrect, as this plunker shows: http://plnkr.co/edit/VI7tF1?p=preview (the scope is destroyed, and previously bound values remain in the DOM, while the ui-view is animated out).

This change in the timing of the $destroy for a ui-view's $scope caused issues for other users, who rely on the original timing and lifecycle, so that lifecycle event listeners are deregistered just before the ui-view is animated out.

We have discussed this issue internally, and I think we can revert to the 0.2.15 behavior of destroying the $scope before the ui-view animates out. We think that exposing the animation promise to a controller function will allow a hook for the "clean up resources on $destroy" crowd to do so after the animation is complete.

Something like <div ui-view on-destroy="vm.scheduleCleanup($event)"></div> and then

function ctrl() {
  this.scheduleCleanup = function(event) {
    event.promise.then(cleanup());
  }
  this.cleanup = functino() {
    //     clean up highcharts resources
  }
}

screen shot 2016-02-17 at 5 16 01 pm

@christopherthielen
Copy link
Contributor Author

released 0.3.0

@adrienlamotte
Copy link

Hi !
Could you explain a bit more how to solve that issue ? I have the exact same kind of issue, and had no luck with your demo code above...

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants