NativeScript Core


The methods provided by timer module allows execution of code fragment at specific time interval. Methods:

  • setTimeout
  • setInterval
const timerModule = require("tns-core-modules/timer");


Timer method setInterval can be used to apply recurring action on given interval in miliseconds

id = timerModule.setInterval(() => {
    const randNumber = Math.floor(Math.random() * (color.length));
    vm.set("buttoncolor", color[randNumber]);
}, 1000);

Improve this document

Demo Source


Timer method setTimeout can be used to delay the execution of an action in miliseconds.

setTimeout(() => {
    vm.set("counter", counter--);
    button.backgroundColor = new Color("#30BCFF");
}, 1000);

Improve this document

Demo Source

API Reference for the Timer Class