troch / angular-multi-step-form

An angular module for creating multi step forms / wizards
http://troch.github.io/angular-multi-step-form
ISC License
144 stars 44 forks source link

$scope.$on('$destroy') not called on the very last step #45

Closed rdzidziguri closed 8 years ago

rdzidziguri commented 8 years ago

for every step i have this implemented so i save isolated scope data into the wizard global Context and this enables easy navigation back and forward, but the issue is that whenever i am on the very last step of the wizard and finish is triggered it does not call $scope.$on('$destroy') on that step which means its context can not be saved.

troch commented 8 years ago

On step transitions, scope are destroys because a new step is created, replacing the existing one. When you supply an onFinish callback, it is up to you to cause the last step to be destroyed by destroying the directive itself (example: navigate away).

rdzidziguri commented 8 years ago

Can u explain a little bit more in details? i mean in my implementation when onfishin is called i have no idea ho to extract data from the very last step so the current global controller inside which multi step form is hosted gets that data. can u provide any example how to force on destroy call on that last step? i mean this directive itself sits in HTML and is bound to controllers steps and onFinish method ok but inside controller i have no idea that steps are destroyed or created and even have no access to the multistepform itself. Plus this is really interesting case as step order is not linear and array of steps get populated and ordered based on data and some other client interaction. so i think prior to calling onFinish last step destroy method could be called.

Below is a dirty hack i came across which works but it looks really really dirty so if u can provide better idea or call destroy in last step before finish this code part could be removed. This is what i have inside one of the steps' isolated scope

var finishMethod = multiStepFormScope.$finish; multiStepFormScope.$finish = function () { multiStepFormScope.vm.ctx.edmRecDefinition = angular.copy(vm.model); finishMethod(); }

troch commented 8 years ago

You should see the multi step form directive like a data presenter, not a data holder. If you need to have data shared between a multi step directive and one of your controllers, use a state container (aka a factory) and share data with dependency injection.

rdzidziguri commented 8 years ago

Your point of view is exactly what i have and it is data presenter itself, but this even does not relate to this case. if u want i can set-up code simple and u can clearly see the point. id does not meter how i construct data the only problem is that if step form has its own scope and this step is the last one in the multistepform if u have onFinish defined in a parent scope which holds directive as a presenter u have still no chance to force this form to pass data back to parent scope.

troch commented 8 years ago

As I said, you need to destroy it yourself. It will get destroyed if it is no longer present in your view: navigate away, display something else...