Can any on help me to send the data from one page to another page using AngularJS.
Service code
var module = angular.module('app', []);
module.service('ContactService', function () {
var uid = 1;
var contacts = [{
id: 0,
'fname': 'Supriya',
'mobile': '8985335701',
'mail': 'hello@gmail.com',
'age': '20',
'gender' : 'female'
}];
this.save = function (contact) {
if (contact.id == null) {
contact.id = uid++;
contacts.push(contact);
} else {
for (i in contacts) {
if (contacts[i].id == contact.id)
{
contacts[i] = contact;
}
}
}
}
this.list = function () {
return contacts;
}
});
Controller code:
module.controller('ContactController', function ($scope, ContactService) {
$scope.contacts = ContactService.list();
$scope.saveContact = function () {
ContactService.save($scope.newcontact);
$scope.newcontact = {};
}
})
Html page:
<body>
<div ng-app="app" ng-controller="ContactController">
<form>
<label>Full Name:</label>
<input type="text" ng-model="newcontact.fname"><br>
<label>Mobile Number:</label>
<input type="text" ng-model="newcontact.mobile"> </br>
<label> E-Mail:</label>
<input type="email" ng-model="newcontact.mail"> </br>
<label> Age:</label>
<input type="text" ng-model="newcontact.age"> </br>
<label> Gender: </label>
<input type="radio" ng-model="newcontact.gender" value="male">Male
<input type="radio" ng-model="newcontact.gender" value="female">Female
<input type="hidden" ng-model="newcontact.id" />
<br>
<input type="button" value="Save" ng-click="saveContact()" />
<table border=1px>
<thead>
<tr>
<th>Full Name</th>
<th>Mobile Number</th>
<th>Email</th>
<th>Age</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contacts">
<td>{{ contact.fname }}</td>
<td>{{ contact.mobile }}</td>
<td>{{ contact.mail }}</td>
<td>{{ contact.age }}</td>
<td>{{ contact.gender }}</td>
</tr>
</tbody>
</table>
</div>
</body>
On click of save button the details which are entered in the form should be send to another page called index.html
.