Uloženie údajov do sessionStorage.
Key: {{key}} Value: {{value}} Storage: {{storage_copy|json}}
<script src=https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js></script>
<div ng-app="myApp" ng-controller="myCtrl">
<form class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-4" for="key">Key:</label>
<div class="col-sm-8">
<input class="form-control" type="text" ng-model="key" placeholder="Vložte kľúč" id="key">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4" for="value">Value:</label>
<div class="col-sm-8">
<input class="form-control" type="text" ng-model="value" placeholder="Vložte hodnotu" id="value">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="button" class="btn btn-default" ng-click="save()">Uložiť</button>
<button type="button" class="btn btn-default" ng-click="load()">Načítať</button>
<button type="button" class="btn btn-default" ng-click="delete()">Vymazať</button>
</div>
</div>
</form>
<hr>
<pre>Key: {{key}}
Value: {{value}}
Storage: {{storage_copy|json}}</pre>
</div>
var app = angular.module('myApp', []);
app.controller('myCtrl', ['$scope', '$window', function($scope, $window) {
$scope.key = 'key1';
$scope.value = 'abc';
$scope.storage_copy = $window.sessionStorage;
$scope.save = function() {
$window.sessionStorage.setItem($scope.key, $scope.value);
$scope.storage_copy = $window.sessionStorage;
};
$scope.load = function() {
$scope.value = $window.sessionStorage.getItem($scope.key);
};
$scope.delete = function() {
$window.sessionStorage.removeItem($scope.key);
$scope.storage_copy = $window.sessionStorage;
};
}]);