I am new in angular js. I have create page where I have to post data to other html page and then I have to receive the data in other page using angular.
I have create a small application. I have post data from home.html page to getdata.html page and on getdata.html page I have to receive that data. I have to get data using form posting only. I have to pass data on header using post request and then I have to receive it
test.js
var mainApp = angular.module("mainApp", ['ngRoute']);
mainApp.config(function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'home.html',
controller: 'StudentController'
}).when('/getdata', {
templateUrl: 'getdata.html',
controller: 'getdataController'
})
.otherwise({
redirectTo: '/home'
});
});
mainApp.controller('StudentController', function($scope,$location,$window) {
$scope.user = {firstName:"John", lastName:"Doe"};
});
mainApp.controller('getdataController',
function($scope,$location,$window,$routeParams) {
alert("Get Data");
});
getdata.html
<div ng-controller='getdataController'>
<h2>Get Data</h2>
</div>
home.html
<div class="container" ng-controller='StudentController'>
<h1>Post Form Data</h1>
<form novalidate method="post" action='http://localhost/#/getdata'>
<input type='hidden' value='Mohan' name="hiddenfld1"/>
<input type='hidden' value='Sharma' name="hiddenfld2"/>
<input type='hidden' value='ABC.com' name="hiddenfld3"/>
First Name:<br>
<input type="text" name='fname' ng-model="user.firstName"><br>
Last Name:<br>
<input type="text" name='lname' ng-model="user.lastName">
<br><br>
<input type="submit" value="Submit">
</form>
</div>
index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
</head>
<body>
<div ng-app="mainApp">
<ng-view></ng-view>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-route.min.js"></script>
<script type="text/javascript" src="test.js"></script>
</body>