yog yog - 3 months ago 21
AngularJS Question

Angularjs step by step form

I am trying to create exactly same form given in this fiddle
steb by step angular form

but whenever i click on the next button data entered in the first step resets.. how can i prevent this? On submit all data is undefined while reading in javascript.

Please help me..

Answer

In the JsFiddle code you provided you are not retaining the users data, meaning that data is being Binded to anything in the controller. So when leave the section the data is removed.

To retain data make the following changes:

// In your controller add the following object to the $scope
   $scope.user = {}

// In your HTML code add the following to your input fields
   <input type="text" id="teamName" ng-model="user.teamName" placeholder="Team Name" />

Notice the ng-model tag in the input field this is what binds your data to the user object within your controller

Heres a working JsFiddle, please note that I only updated the Team Name field. Type something in the Team Name field and go to the next section and it will retain your data. You will need to update the remaining fields.