var yourApp = angular.module("yourApp",[]);
yourApp.controller("View1", function ($rootScope, $scope, $window) {
$rootScope.abc = $scope.fname;
$scope.shareData = function () {
$rootScope.abc = $scope.fname;
$window.location.href = "#/View2";
}
});
yourApp.controller("View2", function ($rootScope, $scope, $window) {
$scope.fname = $rootScope.abc;
});
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title></title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.5.x" src="https://code.angularjs.org/1.5.8/angular.js" data-semver="1.5.8"></script>
<script data-require="angular-route@*" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular-route.js"></script>
<script src="routeApp.js"></script>
<script src="app.js"></script>
</head>
<body>
<h3>
Share data from one conroller to another using $routeScope
</h3>
<div ng-view=""></div>
</body>
</html>
/* Put your css in here */
<div>
<label>Text : </label>
<input type="text" name="fname" value="AbcdXyz" ng-model="fname" />
<a href="" ng-click="shareData()">Link</a>
</div>
<div>
<label>Data :</label>
<input type="text" name="fname" value="" ng-model="fname" readonly />
<a href="index.html#/" ng-click="shareData()">Back</a>
</div>
var myApp = angular.module('myApp', ['ngRoute', 'yourApp']);
myApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/',
{
templateUrl: 'View1.html',
controller: 'View1'
}).
when('/View2',
{
templateUrl: 'View2.html',
controller: 'View2'
}).
otherwise(
{
redirectTo: '/'
});
}]);