我尝试在 .run() 中的 $rootScope 中设置 aa 值并尝试在服务中获取它,但它看起来像是未定义的。.run() 和服务中的其他所有内容都运行良好。
.run(function($ionicPlatform, $translate, $rootScope) {
document.addEventListener("deviceready",function(){ onDeviceReady($rootScope); }, false);
function onDeviceReady($rootScope) {
if(typeof navigator.globalization !== "undefined") {
navigator.globalization.getPreferredLanguage(function(language) {
$rootScope.language='en'; //(language.value).split('-')[0];
$translate.use((language.value).split("-")[0]).then(function(data) {
console.log("SUCCESS -> " + data);
}, function(error) {
console.log("ERROR -> " + error);
});
}, null);
}
}
})
.service('Webcache', function ($http, $q, apiHost, $rootScope) {
return {
getDataBySection: function (section, version, params) {
var params = params || {};
var host = apiHost;
var deferred = $q.defer();
var start = new Date().getTime();
params.lang = $rootScope.language;
$http.get('http://'+ host +'/api/'+ version +'/'+ section, {
cache: true,
params: params
}).success(function (response) {
deferred.resolve(response);
}).error(function (response){
deferred.resolve(false);
});
return deferred.promise;
}
};
})