Angularjs 在OndeviceReady之后配置提供程序
嗨,我正在尝试在angularjs和phonegap中创建一个日志服务,以便在我的手机中写入一些日志 到目前为止,我已经尝试实现一个提供程序,以便可以轻松配置要写入的文件(Angularjs 在OndeviceReady之后配置提供程序,angularjs,cordova,Angularjs,Cordova,嗨,我正在尝试在angularjs和phonegap中创建一个日志服务,以便在我的手机中写入一些日志 到目前为止,我已经尝试实现一个提供程序,以便可以轻松配置要写入的文件(window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail);)以及是否要在外部文件中写入日志 问题是如果我在OnDeviceReady事件中包装配置行,则提供程序的配置无法正常工作 所以我的问题是,既然我希望有一个全局变量来将所有内容写入同一个文件中,那么
window.requestFileSystem(LocalFileSystem.PERSISTENT,0,gotFS,fail);
)以及是否要在外部文件中写入日志
问题是如果我在OnDeviceReady事件中包装配置行,则提供程序的配置无法正常工作
所以我的问题是,既然我希望有一个全局变量来将所有内容写入同一个文件中,那么如何配置一个需要在OnDeviceReady之后执行的提供程序
app.js的实现
MyApp.config(['$routeProvider','$httpProvider','logItProvider', function ($routeProvider, $httpProvider, logIt) {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("deviceReady!");
var file = "myFile";
logIt.setFile(file);
logIt.setLogEnable(true);
}
这是my provider的实现:
angular.module('logger', [])
.provider('logIt', function(){
// internal configuration data; configured through setter function
this.file = 'Default';
this.callsParseCounter = 0;
this.isLogEnable = false;
this.$get = function() {
var file = this.file;
var numberOfCalls = this.callsParseCounter;
var isLogEnable = this.isLogEnable;
return {
getFile: function() {
return "Hello, " + file + "!"
},
writeLog: function(message){
if(this.isLogEnable)
{
}
},
incrementParseCounter: function()
{
if(isLogEnable)
{
numberOfCalls++;
this.callsParseCounter = numberOfCalls;
}
},
getNumberOfCalls: function(){
return numberOfCalls;
}
}
};
this.setFile = function(file) {
this.file = file;
};
this.setCallParseCounter = function(callsParseCounter)
{
this.callsParseCounter = callsParseCounter;
};
this.setLogEnable = function(isLogEnable)
{
this.isLogEnable = isLogEnable;
}
});
也许你可以在设备准备好后手动引导angular?这是文件: