<!DOCTYPE html>
<html
ng-app="localStorageExample">
<head>
<title>Angularjs Local Storage</title>
<script src="angular.js"></script>
<script src="ngStorage.js"></script>
<meta charset="utf-8" />
OR
<script type="text/javascript">
var app = angular.module('localStorageExample', ["ngStorage"]);
app.controller('myController',
['$scope', '$localStorage','$sessionStorage', function ($scope, $localStorage,
$sessionStorage) {
$scope.Store = function () {
$localStorage.LocalMessage =
$scope.name;
$sessionStorage.SessionMessage
= $scope.Sessionname;
}
$scope.name =
$localStorage.LocalMessage;
$scope.Sessionname = $sessionStorage.SessionMessage;
$scope.Clear = function () {
$localStorage.$reset();
$sessionStorage.$reset();
}
}]);
</script>
<script type="text/javascript">
app.controller('myController',
['$scope',function ($scope) {
var
localstorage = window.localStorage;
var
sessionstrore = window.sessionStorage;
$scope.Store = function () {
localstorage.setItem("StorageInfo", $scope.name);
sessionstrore.setItem("StoreSession", $scope.Sessionname);
}
$scope.name = localstorage.getItem("StorageInfo");
$scope.Sessionname =
sessionstrore.getItem("StoreSession");
$scope.Clear = function () {
localstorage.clear();
sessionstrore.clear();
}
}]);
</script>
</head>
<body
ng-controller="myController">
<input type="text" ng-model="name" placeholder="local " /><br />
<input type="text" value="" ng-model="Sessionname" placeholder="Session" /><br />
<input type="button" ng-click="Store()" value="Store" />
<input type="button" value="Clear" ng-click="Clear()" /><br />
Local Storage Value :<label>{{name}}</label><br />
Session Storage Value :<label>{{Sessionname}}</label>
</body>
</html>
No comments:
Post a Comment