Prev Demo
AngularJS
>
Add Into Cache
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script> </head> <body> <script> var app = angular.module("app", []); app.controller("CacheController", ['$scope', '$cacheFactory', function ($scope, $cacheFactory) { $scope.cacheKeys = []; $scope.cacheObject = $cacheFactory("newCacheInstance"); $scope.add = function (key, value) { $scope.cacheObject.put(key, value); $scope.cacheKeys.push(key); }; }]); </script> <div ng-app="app" ng-controller="CacheController"> Cache key: <input type="text" ng-model="cacheKey" placeholder="cacheKey"/> Cache value: <input type="text" ng-model="cacheValue" placeholder="cacheValue" /> <div><br /> <button ng-click="add(cacheKey, cacheValue)">Add</button> </div> <hr /> <ol> <li ng-repeat="key in cacheKeys"> <span ng-bind="key"></span> : <span ng-bind="cacheObject.get(key)"></span> </li> </ol> <b>Cache info</b> <ul> <li ng-repeat="(key, value) in cacheObject.info()"> <span ng-bind="key"></span> : <span ng-bind="value"></span> </li> </ul> </div> </body> </html>
Note: We DO NOT save your trial code in our database.
Output