This is a migrated thread and some comments may be shown as answers.

localStorageApp is not defined

1 Answer 68 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
XiMnet Malaysia
Top achievements
Rank 1
XiMnet Malaysia asked on 11 Nov 2014, 01:09 PM
Hi,

Was trying to use localStorageApp as below, but in the emulator debugger, I get error : Uncaught ReferenceError: localStorageApp is not defined.
What am I missing?
Thanks.

var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicity call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        navigator.splashscreen.hide();
          localStorageApp = new localStorageApp();
          localStorageApp.run();
         
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');
 
        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');
 
        console.log('Received Event: ' + id);
    }
};

1 Answer, 1 is accepted

Sort by
0
Accepted
Kaloyan
Telerik team
answered on 14 Nov 2014, 09:05 AM
Hi XiMnet Malaysia,

I am not sure if I have fully understood your inquiry, so, please correct me if needed.

In order to use Local Storage in hybrid apps, you need to access the localstorage object, instead of localStorageApp. For example, like this:
onDeviceReady: function() {
    app.receivedEvent('deviceready');
    navigator.splashscreen.hide();
     
    localStorage.setItem("lastname", "Smith");
},
More about local storage, can be found in the Cordova documentation or here. You can also check the AppBuilder's Local Storage sample.

Further, if the localStorageApp is an object, different than the webview's local storage, I suggest to check if it is set on global level, or if the needed references are present in order to access it.

I hope this helps.

Regards,
Kaloyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
XiMnet Malaysia
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Share this question
or