我有以下提供程序导致应用程序不执行任何操作,但控制台上没有错误...我已经查看了几个小时但无济于事。
(function (angular) {
"use strict";
angular.module('app').provider('templateRepository', function () {
var templateKey = 'template:',
useCache = true,
cacheDuration = 30,
autoCleanCache = true,
cleanCacheInterval = 30;
return {
$get: ['$http', '$q', '$interval', function ($http, $q, $interval) {
var getFromCache = function (key) {
return JSON.parse(localStorage.getItem(key));
},
getFromServer = function (name) {
return $http.get('Template/Index?name=' + name).then(function (response) {
return response.data;
});
},
isExpired = function (item) {
return ((parseInt(new Date() - new Date(item.timestamp)) / (1000 * 60)) >= cacheDuration);
},
removeFromCache = function (key) {
localStorage.removeItem(key);
},
saveToCache = function (key, value) {
localStorage.setItem(key, JSON.stringify({
timestamp: new Date().toUTCString(),
value: value
}));
},
cleanCache = function () {
for (var key in localStorage) {
if (key.substring(0, 9) === templateKey) {
if (isExpired(JSON.parse(localStorage.getItem(key)))) {
removeFromCache(key);
}
}
}
};
if (useCache && autoCleanCache) {
$interval(function () {
cleanCache();
}, (cleanCacheInterval * 60 * 1000));
}
return {
get: function (name) {
var key = templateKey + name,
d = $q.defer(),
item;
if (useCache) {
item = getFromCache(key);
if (item === null) {
getFromServer(name).then(function (template) {
saveToCache(key, template);
d.resolve(template);
});
} else {
if (isExpired(item)) {
getFromServer(name).then(function (template) {
saveToCache(key, template);
d.resolve(template);
});
} else {
d.resolve(item.value);
}
}
} else {
getFromServer(name).then(function (template) {
d.resolve(template);
});
}
return d.promise;
}
};
}],
configureCache: function (enable, duration, autoClean, cleanInterval) {
useCache = enable;
cacheDuration = duration;
autoCleanCache = autoClean;
cleanCacheInterval = cleanInterval;
}
};
});
}(this.angular));
答案 0 :(得分:1)
我使用http://jscompress.com/缩小,其余的应用程序运行正常。无论如何我都没有测试你的代码。也许尝试以下缩小的代码或分享您的缩小的js。
(function(e){"use strict";e.module("app").provider("templateRepository",function(){var e="template:",t=true,n=30,r=true,i=30;return{$get:["$http","$q","$interval",function(s,o,u){var a=function(e){return JSON.parse(localStorage.getItem(e))},f=function(e){return s.get("Template/Index?name="+e).then(function(e){return e.data})},l=function(e){return parseInt(new Date-new Date(e.timestamp))/(1e3*60)>=n},c=function(e){localStorage.removeItem(e)},h=function(e,t){localStorage.setItem(e,JSON.stringify({timestamp:(new Date).toUTCString(),value:t}))},p=function(){for(var t in localStorage){if(t.substring(0,9)===e){if(l(JSON.parse(localStorage.getItem(t)))){c(t)}}}};if(t&&r){u(function(){p()},i*60*1e3)}return{get:function(n){var r=e+n,i=o.defer(),s;if(t){s=a(r);if(s===null){f(n).then(function(e){h(r,e);i.resolve(e)})}else{if(l(s)){f(n).then(function(e){h(r,e);i.resolve(e)})}else{i.resolve(s.value)}}}else{f(n).then(function(e){i.resolve(e)})}return i.promise}}}],configureCache:function(e,s,o,u){t=e;n=s;r=o;i=u}}})})(this.angular)