当我的应用程序模拟到Android模拟器时,CordovaLog给我一个错误无法调用 方法setOptions of undefined。在我的Chrome浏览器中我没有问题但是当我模仿它时结果不好,不加载我的所有视图但是它的一部分并且不起作用。任何人都告诉我如何定义setOptions或者为什么未定义
(function () {
'use strict';
angular.module('EventList').factory('EventApi', [ '$http', '$q', '$ionicLoading', 'DSCacheFactory', EventApi]);
function EventApi($http, $q, $ionicLoading, DSCacheFactory)
{
var AllEventCache = DSCacheFactory.get("AllEventDataCache");
AllEventCache.setOptions({
onExpire: function (key, value) {
getAllEvents()
.then(function () {
console.log("Automatically refreshed");
}, function () {
console.log("Error putting Expired data");
AllEventCache.put(key, value);
});
}
});
})();
.run(function ($ionicPlatform, DSCacheFactory) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
var AllEventCache = DSCacheFactory("AllEventDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
});
})
答案 0 :(得分:3)
我想我有解决方案。我在iOs中遇到了同样的问题(它适用于Localhost,但是当在xcode中构建时,它不起作用......所以与你的android情况非常相似)。如果你像Chrome一样刷新耦合时间,你也会看到同样的错误。
问题是,你需要把你的
DSCacheFactory("AllEventDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
进入你的工厂。而不是在运行中定义你的AllEventCache(在我假设的app.js文件中?),将其取出并直接在你的工厂js文件中定义如下:
angular.module('EventList').factory('EventApi', [ '$http', '$q', '$ionicLoading', 'DSCacheFactory', EventApi]);
function EventApi($http, $q, $ionicLoading, DSCacheFactory)
{
DSCacheFactory("AllEventDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
var AllEventCache = DSCacheFactory.get("AllEventDataCache");
AllEventCache.setOptions({
onExpire: function (key, value) {
getAllEvents()
.then(function () {
希望这也适合你:)