Skip to content

Commit 080ac5a

Browse files
Trevor Ewenbtford
Trevor Ewen
authored andcommitted
docs($cacheFactory): add example
1 parent e14d1a7 commit 080ac5a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/ng/cacheFactory.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,46 @@
3737
* - `{void}` `removeAll()` — Removes all cached values.
3838
* - `{void}` `destroy()` — Removes references to this cache from $cacheFactory.
3939
*
40+
* @example
41+
<example module="cacheExampleApp">
42+
<file name="index.html">
43+
<div ng-controller="CacheController">
44+
<input ng-model="newCacheKey" placeholder="Key">
45+
<input ng-model="newCacheValue" placeholder="Value">
46+
<button ng-click="put(newCacheKey, newCacheValue)">Cache</button>
47+
48+
<p ng-if="keys.length">Cached Values</p>
49+
<div ng-repeat="key in keys">
50+
<span ng-bind="key"></span>
51+
<span>: </span>
52+
<b ng-bind="cache.get(key)"></b>
53+
</div>
54+
55+
<p>Cache Info</p>
56+
<div ng-repeat="(key, value) in cache.info()">
57+
<span ng-bind="key"></span>
58+
<span>: </span>
59+
<b ng-bind="value"></b>
60+
</div>
61+
</div>
62+
</file>
63+
<file name="script.js">
64+
angular.module('cacheExampleApp', []).
65+
controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
66+
$scope.keys = [];
67+
$scope.cache = $cacheFactory('cacheId');
68+
$scope.put = function(key, value) {
69+
$scope.cache.put(key, value);
70+
$scope.keys.push(key);
71+
};
72+
}]);
73+
</file>
74+
<file name="style.css">
75+
p {
76+
margin: 10px 0 3px;
77+
}
78+
</file>
79+
</example>
4080
*/
4181
function $CacheFactoryProvider() {
4282

0 commit comments

Comments
 (0)