angularjs的cache

 首先要引入angular-cookies.js插件

angular.module('app').service('cache', ['$cookies', function($cookies){
    this.put = function(key, value){
      $cookies.put(key, value);
    };
    this.get = function(key) {
      return $cookies.get(key);
    };
    this.remove = function(key) {
      $cookies.remove(key);
    };
}]);

  写一个服务,方便调用,加入服务cache

angular.module('app').controller('goodsCtrl', ['cache','$http','$state', '$scope',function(cache,$http,$state, $scope){

  使用:

cache.put('id',result[0].id);
cache.put('Tel',result[0].Tel);
 cache.put('UserName',result[0].UserName);

  

原文地址:https://www.cnblogs.com/chenlw/p/9494525.html