Help guide the NativeScript roadmap! Participate in the community survey. 📝

NativeScript Angular

Application Settings

The Application settings allows you to save and restore any kind of information related to your application. Using application settings methods requires to load "Application Settings" module.

Values

Using application settings methods requires to load "application settings" module.

Basic usage of the application-settings module in a component:

import {
    getBoolean,
    setBoolean,
    getNumber,
    setNumber,
    getString,
    setString,
    hasKey,
    remove,
    clear
} from "tns-core-modules/application-settings";

Set and get boolean value and provide default value in case it is not set

setBoolean("isTurnedOn", true);
this.isTurnedOn = getBoolean("isTurnedOn", true);

Set and get string value

setString("username", "Wolfgang");
this.username = getString("username");

Set and get numeric value.

setNumber("locationX", 54.321);
this.locationX = parseFloat(getNumber("locationX").toFixed(3));

Reading values that are not set before while providing default value

// will return "No string value" if there is no value for "noSuchKey"
this.someKey = getString("noSuchKey", "No string value");

Reading values that are not set before not providing default value

// will return undefined if there is no value for "noSuchKey"
let defaultValue = getString("noSuchKey");
console.log(defaultValue);

Checking for existence of value for key

// will return false if there is no value for "noBoolKey"
this.noBoolKey = hasKey("noBoolKey");

Removing value for key

remove("isTurnedOn");

Removing all values

clear();

Improve this document

Demo Source


API Reference for Application Settings