Dialogs

Displaying dialogs requires the "ui/dialogs" module.

import * as dialogs from "tns-core-modules/ui/dialogs";

Action

var options = {
    title: "Race Selection",
    message: "Choose your race",
    cancelButtonText: "Cancel",
    actions: ["Human", "Elf", "Dwarf", "Orc"]
};
dialogs.action(options).then((result) => { 
    console.log(result);
});

Confirm

var options = {
    title: "Race Selection",
    message: "Are you sure you want to be an Elf?",
    okButtonText: "Yes",
    cancelButtonText: "No",
    neutralButtonText: "Cancel"
};
dialogs.confirm(options).then((result: boolean) => {
    // result can be true/false/undefined
    console.log(result);
});

Alert

var options = {
    title: "Race Selection",
    message: "Race Chosen: Elf",
    okButtonText: "OK"
};
dialogs.alert(options).then(() => {
    console.log("Race Chosen!");
});

Login

var options = {
    title: "Login",
    message: "Login",
    username: "john_doe",
    password: ""
};
dialogs.login(options).then((loginResult: dialogs.LoginResult) => {
    // true or false.
    console.log(loginResult.result);
});

Prompt

var options = {
    title: "Name",
    defaultText: "Enter your name",
    inputType: dialogs.inputType.text
};
dialogs.prompt(options).then((result: dialogs.PromptResult) => { 
    console.log("Hello, " + result.text);
});

Stay connected with NativeScript

(expect a newsletter every 4-8 weeks)

NativeScript
NativeScript is licensed under the Apache 2.0 license .
© Progress Software Corporation. All Rights Reserved.