1

こんにちは、angularjs と phonegap でログ サービスを作成して、モバイルにログを書き込もうとしています。

これまでのところ、プロバイダーの実装を試みたので、書き込むファイル ( ) を簡単に構成でき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);

    }

これは私のプロバイダーの実装です:

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;
        }

    });
4

0 に答える 0