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

form is not accessible in controllers #26

Closed bagwanpankaj closed 8 years ago

bagwanpankaj commented 8 years ago

When steps are used with templateUrl, form is not accessible in controller even not in multi-step-container

troch commented 8 years ago

Can you give me an example to reproduce? Thanks.

bagwanpankaj commented 8 years ago

I put up a bare minimum angular app here. MultiStep form can be found at /#/about. The issue is as follows

1.) angular form object is available within the template it is defined (step_1.html and step_2.html templates) 2.) angular form object is not available in wrapper template that defines <multi-step-container steps="steps"> (defined in about.html) 3.) angular form object is not available in AboutCtrl. Since it can not pased as well via nextStep function, see point#2

troch commented 8 years ago

I think this is expected. The form object (from Angular's <form> directive) will be added to the scope of the step it is in. Therefore you cannot access it from either the scope of the multi-step form directive or your surrounding scope (used by AboutCtrl).

What you can do is something similar to this: https://github.com/troch/angular-multi-step-form/blob/master/src/directives/form-step-validity.js. With a custom directive, you can grab your form instance (formCtrl) and pass it to another controller or factory.

bagwanpankaj commented 8 years ago

Got that. Thanks

troch commented 8 years ago

One another thing you can do, depending on your use case, is to have a surrounding <form> rather than forms in each step.