I am trying to create a multi step form in which I have made two different views and two different controllers I am trying to pass the data from view 1 to function defined in service and then trying to access this data in another function of same service. The following is the service I have written: service.js
var EmployeeService = angular.module('EmployeeService',[])
.service('AddEmployee', function($resource){
var Employee = $resource('/api/meetups');
var emp_email="";
this.email = function(email){
var emp_email = email;
return emp_email;
};
this.personal = function(first_name){
var employee = new Employee();
employee.email = emp_email;
employee.first_name = first_name;
employee.$save();
};
});
I am trying access emp_email variable of email function into personal function. but I am not able to do so. is there any way I can use emp_email variable in my second function.
Following is the controller which is using services:
app.controller('mainCrl', ['$scope', '$resource', '$location', 'AddEmployee', function ($scope, $resource, $location, AddEmployee){
$scope.nextSection = function(){
$scope.email = AddEmployee.email($scope.employeeEmail);
};
}]);
app.controller('secondCrl', ['$scope', '$resource', '$location', 'AddEmployee', function ($scope, $resource, $location, AddEmployee){
$scope.secondSection = function(){
$scope.first_name = AddEmployee.personal($scope.first_name);
};
}]);
nextSection function will be executed when user fills email and hits on next section and secondSection function will be executed when user enters first_name in second view and hits submit.
how can I pass the data between two functions in services? any sort of help is really appreciated!!!!