CacheFactory 在我的浏览器中工作但在我的 apk 中不工作
CacheFactory working in my browser but not working in my apk
我已将 angular-缓存添加到我的应用程序,并创建了我的项目,如下所示:
angular.module('rotaryApp', ["ionic", "angular-cache"])
.run(function($ionicPlatform, CacheFactory) {
$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();
}
CacheFactory("songsDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("versesCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("chorusCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("imageCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("searchCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
//CacheFactory("myTeamsCache", { storageMode: "localStorage" });
//CacheFactory("staticCache", { storageMode: "localStorage" });
});
})
我的服务如下所示:
(function () {
'use strict';
angular.module('rotaryApp').factory('eliteApi', ['$http', '$q', '$ionicLoading','CacheFactory', eliteApi]);
function eliteApi($http,$q,$ionicLoading,CacheFactory ) {
var songid;
self.songsDataCache = CacheFactory.get("songsDataCache");
self.versesCache = CacheFactory.get("versesCache");
self.chorusCache = CacheFactory.get("chorusCache");
function getLeagues(){
var defered = $q.defer(),
cacheKey = "songs",
songsData = self.songsDataCache.get(cacheKey);
if(songsData){
console.log("found data in cache");
defered.resolve(songsData);
} else {
$ionicLoading.show({template: 'Loading Songs...'})
var url = "http://bestng.com/notrealurl";
$http.get(url)
.success(function (data) {
$ionicLoading.hide();
console.log("Received data via HTTP");
self.songsDataCache.put(cacheKey, data);
defered.resolve(data);
})
.error(function (data){
defered.reject();
});
}
return defered.promise;
}
function setSongid(sid){
songid = sid;
}
return {
getLeagues: getLeagues,
getLeaguesByTitle: getLeaguesByTitle,
getVerse:getVerse,
getChorus:getChorus,
getLeagueData: getLeagueData,
setSongid: setSongid
};
};
})();
下面是我的控制器:
(function () {
'use strict';
angular.module('rotaryApp').controller('LeaguesCtrl', ['$state', 'eliteApi', LeaguesCtrl]);
function LeaguesCtrl($state, eliteApi) {
var vm = this;
eliteApi.getLeagues().then(function(data){
vm.leagues = data;
});
};
})();
当我不 'ionic serve' 时,getLeagues 函数在我的浏览器中工作正常,但一旦我这样做 'ionic emulate android' 它只是返回一个空白屏幕。
请帮助我了解为什么这在我的浏览器中有效但在我的 apk 中无效。
感谢您的宝贵时间。
此致
缓存工厂必须在 ionicPlatform.ready()
外部声明,但在 run(function(){ ...})
内部
将我在问题中的 app.js 与下面的工作 app.js 进行比较:
angular.module('rotaryApp', ["ionic", "angular-cache"])
.run(function($ionicPlatform, CacheFactory) {
$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();
}
}); // end of ready()
CacheFactory("songsDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("versesCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("chorusCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("imageCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("searchCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
}); // end of run(function(){..})
这对我有用。希望对你也有用
我已将 angular-缓存添加到我的应用程序,并创建了我的项目,如下所示:
angular.module('rotaryApp', ["ionic", "angular-cache"])
.run(function($ionicPlatform, CacheFactory) {
$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();
}
CacheFactory("songsDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("versesCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("chorusCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("imageCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("searchCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
//CacheFactory("myTeamsCache", { storageMode: "localStorage" });
//CacheFactory("staticCache", { storageMode: "localStorage" });
}); })
我的服务如下所示:
(function () {
'use strict';
angular.module('rotaryApp').factory('eliteApi', ['$http', '$q', '$ionicLoading','CacheFactory', eliteApi]);
function eliteApi($http,$q,$ionicLoading,CacheFactory ) {
var songid;
self.songsDataCache = CacheFactory.get("songsDataCache");
self.versesCache = CacheFactory.get("versesCache");
self.chorusCache = CacheFactory.get("chorusCache");
function getLeagues(){
var defered = $q.defer(),
cacheKey = "songs",
songsData = self.songsDataCache.get(cacheKey);
if(songsData){
console.log("found data in cache");
defered.resolve(songsData);
} else {
$ionicLoading.show({template: 'Loading Songs...'})
var url = "http://bestng.com/notrealurl";
$http.get(url)
.success(function (data) {
$ionicLoading.hide();
console.log("Received data via HTTP");
self.songsDataCache.put(cacheKey, data);
defered.resolve(data);
})
.error(function (data){
defered.reject();
});
}
return defered.promise;
}
function setSongid(sid){
songid = sid;
}
return {
getLeagues: getLeagues,
getLeaguesByTitle: getLeaguesByTitle,
getVerse:getVerse,
getChorus:getChorus,
getLeagueData: getLeagueData,
setSongid: setSongid
};
};
})();
下面是我的控制器:
(function () {
'use strict';
angular.module('rotaryApp').controller('LeaguesCtrl', ['$state', 'eliteApi', LeaguesCtrl]);
function LeaguesCtrl($state, eliteApi) {
var vm = this;
eliteApi.getLeagues().then(function(data){
vm.leagues = data;
});
};
})();
当我不 'ionic serve' 时,getLeagues 函数在我的浏览器中工作正常,但一旦我这样做 'ionic emulate android' 它只是返回一个空白屏幕。 请帮助我了解为什么这在我的浏览器中有效但在我的 apk 中无效。
感谢您的宝贵时间。
此致
缓存工厂必须在 ionicPlatform.ready()
外部声明,但在 run(function(){ ...})
内部
将我在问题中的 app.js 与下面的工作 app.js 进行比较:
angular.module('rotaryApp', ["ionic", "angular-cache"])
.run(function($ionicPlatform, CacheFactory) {
$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();
}
}); // end of ready()
CacheFactory("songsDataCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("versesCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("chorusCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("imageCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
CacheFactory("searchCache", { storageMode: "localStorage", maxAge: 360000, deleteOnExpire: "aggressive" });
}); // end of run(function(){..})
这对我有用。希望对你也有用