UWP: How to access ApplicationData

0

I am trying to create a Settings Value for my UWP-JS App on Startup.
I am following this Documentation.

Here is what I've currently got:

(function () {
    "use strict"

    //Initialization
    var localSettings = Windows.Storage.ApplicationData.current.localSettings;
    // Save value
    localSettings.Values["exampleSetting"] = "example";
    // Retrieve value
    $('p').text(localSettings.Values["exampleSetting"]);
})();

When I start the Application it enters 'Break Mode' with the following exception in line 7 of the given code:

0x800a138f - JavaScript runtime error: Unable to set property 'exampleSetting' of undefined or null reference


What am I doing wrong?

javascript
visual-studio
winapi
uwp
local-storage
asked on Stack Overflow Feb 23, 2017 by jonhue • edited Feb 23, 2017 by jonhue

1 Answer

1

You are missing the current property, which is also mentioned in the example you refered to. So your call should be:

(function () {
    "use strict"

    //Initialization
    var localSettings = Windows.Storage.ApplicationData.current.localSettings;
    // Save value
    localSettings.values["exampleSetting"] = "example";
    // Retrieve value
    $('p').text(localSettings.values["exampleSetting"]);
})();

Edit:
The properties and method names after Windows.Storage.ApplicationData need to be start with lowercase.

answered on Stack Overflow Feb 23, 2017 by TheTanic • edited Feb 23, 2017 by TheTanic

User contributions licensed under CC BY-SA 3.0