Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJs如何筛选$cacheFactory_Angularjs_Caching - Fatal编程技术网

AngularJs如何筛选$cacheFactory

AngularJs如何筛选$cacheFactory,angularjs,caching,Angularjs,Caching,我有一个$cacheFactory 它用于我的布局Ctrl: 我可以随意过滤该缓存吗?类似于…… 我意识到“$filter(router)”的语法不正确,但我可以使用任何语法吗?您需要手动跟踪密钥-请参阅此链接 /* @ngInject */ MenuSvcCache.$inject = ['$cacheFactory']; app.factory('MenuSvcCache', MenuSvcCache); function MenuSvcCache($cacheFactory){

我有一个$cacheFactory

它用于我的布局Ctrl:

我可以随意过滤该缓存吗?类似于……


我意识到“$filter(router)”的语法不正确,但我可以使用任何语法吗?

您需要手动跟踪密钥-请参阅此链接

 /* @ngInject */
MenuSvcCache.$inject = ['$cacheFactory'];

app.factory('MenuSvcCache', MenuSvcCache);
function MenuSvcCache($cacheFactory){
    return $cacheFactory('MenuSvc')
};
    function Init(router) {
    if (MenuSvcCache) {
        layout.menuItems = MenuSvcCache.get('MenuSvc');            
    } else {
        MenuSvc.all().success(function (data) {
            MenuSvcCache.put('MenuSvc', data)
            layout.menuItems = MenuSvcCache.get('MenuSvc');
        })
            .error(function (error) {
                console.log('Error: ' + error.message)
            });
    }
}
        if(MenuSvcCache && router){   
        layout.menuItems = MenuSvcCache.get('MenuSvc').$filter(router);   
        } else {
        layout.menuItems = MenuSvcCache.get('MenuSvc'); 
        }     
(function(angular) {
  'use strict';
angular.module('cacheExampleApp', []).
  controller('CacheController', ['$filter', '$scope', '$cacheFactory',
  function($filter, $scope, $cacheFactory) {
    $scope.keys = [];
    $scope.cache = $cacheFactory('cacheId');
    $scope.put = function(key, value) {
      if ($scope.cache.get(key) === undefined) {
        $scope.keys.push(key);
      }
      $scope.cache.put(key, value === undefined ? null : value);
    };

    $scope.put('apples', {data: 1});
    $scope.put('pears', {data: 2});
    $scope.put('oranges', {data: 3});
    $scope.put('pineapples', {data: 1});
    $scope.put('cherries', {data: 1});

  }]);
})(window.angular);

angular.module('cacheExampleApp').filter('onesOnly', function() {
  return function(cacheEntry) {
      return cacheEntry.data === 1;
  }
})