I have a multi step form in angularjs. I am using ui-router for routing between different views and ngResource for sending data to mongodb. my problem is that I am not able to send the all the values of form directly into database since form is split into multiple views. when I submit the form with ng-submit, only the values of that view is being sent to database.
index.html
<body>
<div ui-view></div>
</body>
multiple views (register.html)
<div class="row">
<div>
<div id="form-container">
<div class="page-header">
<h2 class="text-center">Enter the following details</h2>
<!-- the links to our nested states using relative paths -->
<!-- add the active class if the state matches our ui-sref -->
<div id="status-buttons" class="text-center link-colors">
<a ui-sref-active="active" ui-sref="/registration_form.signUp"><span>1</span> Setup</a>
<a ui-sref-active="active" ui-sref="/registration_form.personalDetails" ng-disabled="myForm.email.$invalid"><span>2</span> Personal Details</a>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<form name="myForm" role="form" class="form-horizontal" id="signup-form" ng-submit="createMeetup()" enctype="multipart/form-data" novalidate>
<!-- our nested state views will be injected here -->
<div class="form-elements" id="form-views" ui-view></div>
</form>
</div>
<div class="container">
<form name="myForm" role="form" class="form-horizontal" id="signup-form" ng-submit="createMeetup()" enctype="multipart/form-data" novalidate>
<!-- our nested state views will be injected here -->
<div class="form-elements" id="form-views" ui-view></div>
</form>
</div>
inside this view there will be two form views
signUP.html
<label >Email</label>
<div >
<input type="email" name="email" ng-model="employeeEmail" placeholder="email" class="form-control" required>
<span ng-show="myForm.email.$error.email">Invalid Email.</span>
</div>
<a ui-sref="/registration_form.personalDetails">next section</a>
personalDetails.html
<label>First Name</label>
<div >
<input type="text" ng-model="first_name" class="form-control">
</div>
<button type="submit" name="submit">save</button>
I have written the following controller: app.js
var app = angular.module('meetupApp', ['ngResource','ui.router']);
app.controller('mainCrl', ['$scope', '$resource', '$location', function ($scope, $resource, $location) {
var Employee = $resource('/api/meetups');
$scope.employees = [];
$scope.nextPage = function(){
$scope.email = $scope.employeeEmail;
}
$scope.createMeetup = function () {
var employee = new Employee();
employee.email = $scope.employeeEmail;
employee.first_name = $scope.first_name;
employee.$save(function (result) {
});
}
}]);
app.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('/',{
url:'/',
templateUrl:'index.html',
controller: 'mainCrl'
})
.state('/registration_form',{
url:'/registration_form',
templateUrl: 'register.html',
controller: 'mainCrl'
})
.state('/registration_form.signUp',{
url:'/registration_form.signUp',
templateUrl:'signUp.html',
controller:'mainCrl'
})
.state('/registration_form.personalDetails',{
url:'/registration_form.personalDetails',
templateUrl:'personalDetails.html',
controller:'mainCrl'
})
$urlRouterProvider.otherwise('/');
});
so whenever I click the submit button only the values on the personalDetails.html view is saved in database.... the values of signUp.html view is lost while routing. how can I resolve this problem. Sorry of such a long question.