I'm trying to figure out reasonable approaches in AngularJS for creating a function that is composed of multiple steps (i.e., a wizard) but is linked to one page/URL. The data from one step would have to send data to (or share data with) the next step.
The main points are:
- the url should remain the same (i.e.,
http://mydomain/myapp/nameupdater
) for all of the steps and, - the data can be sent amongst steps (i.e., I have to give the data found from step 1 to populate the data in step 2).
For example, suppose that I have a function that does a bulk update of names:
- In step 1 the function makes you search for a name.
- In step 2 the function presents a list of names that were found from step 1 and allows the user to edit them.
I started an approach where each step had its own view and controller. And, the angular-ui-router
maintained the states of the function. But, I have no idea how I would share the data between the steps.
Does anyone know of a good approach to establishing multi-step/wizard forms in angularjs?
My Plunker code is here of my very weak attempt at this.
I think the best way of doing this would be to use
ng-switch
, just one controller, one route, no reload, using variables shared in all steps, like this:This way you can also manipulate the URL to add a step at the end of your current location.
UPDATE :
Actually this answer is for long time ago , this days I personally prefer to use ui-router which is a great module which you can inject to your AngularJs application and make it even more cool with nested views . Speaking of nested views , bellow is my new approach for a multystep form with some animation :
First :
Then later in our "wizard.html" we can have something like this :
And obviously for our steps , we must have seperated html files. This way , we still have one controller , url will be updated , and we can also add angular animation .