mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-06 22:35:22 +08:00
docs($cacheFactory): add example
This commit is contained in:
@@ -37,6 +37,46 @@
|
||||
* - `{void}` `removeAll()` — Removes all cached values.
|
||||
* - `{void}` `destroy()` — Removes references to this cache from $cacheFactory.
|
||||
*
|
||||
* @example
|
||||
<example module="cacheExampleApp">
|
||||
<file name="index.html">
|
||||
<div ng-controller="CacheController">
|
||||
<input ng-model="newCacheKey" placeholder="Key">
|
||||
<input ng-model="newCacheValue" placeholder="Value">
|
||||
<button ng-click="put(newCacheKey, newCacheValue)">Cache</button>
|
||||
|
||||
<p ng-if="keys.length">Cached Values</p>
|
||||
<div ng-repeat="key in keys">
|
||||
<span ng-bind="key"></span>
|
||||
<span>: </span>
|
||||
<b ng-bind="cache.get(key)"></b>
|
||||
</div>
|
||||
|
||||
<p>Cache Info</p>
|
||||
<div ng-repeat="(key, value) in cache.info()">
|
||||
<span ng-bind="key"></span>
|
||||
<span>: </span>
|
||||
<b ng-bind="value"></b>
|
||||
</div>
|
||||
</div>
|
||||
</file>
|
||||
<file name="script.js">
|
||||
angular.module('cacheExampleApp', []).
|
||||
controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
|
||||
$scope.keys = [];
|
||||
$scope.cache = $cacheFactory('cacheId');
|
||||
$scope.put = function(key, value) {
|
||||
$scope.cache.put(key, value);
|
||||
$scope.keys.push(key);
|
||||
};
|
||||
}]);
|
||||
</file>
|
||||
<file name="style.css">
|
||||
p {
|
||||
margin: 10px 0 3px;
|
||||
}
|
||||
</file>
|
||||
</example>
|
||||
*/
|
||||
function $CacheFactoryProvider() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user