import { Observable } from "@nativescript/core" ; import { getText , getTextSync , setText , setTextSync } from "nativescript-clipboard" ; export class HomeViewModel extends Observable { public clipboardText : string ; constructor ( ) { super ( ) ; this . clipboardText = "Tap a button above.." ; } public setTextAsync ( ) { setText ( "I was written Async @ " + new Date ( ) ) . then ( ( ) => this . feedback ( "Wrote to the clipboard" ) ) . catch ( ( err ) => this . feedback ( `Error: ${ err }` ) ) ; } public getTextAsync ( ) { getText ( ) . then ( ( text ) => this . feedback ( text ) ) . catch ( ( err ) => this . feedback ( `Error: ${ err }` ) ) ; } public setTextSync ( ) { setTextSync ( "I was written sync @ " + new Date ( ) ) ; this . feedback ( "Wrote to the clipboard" ) ; } public getTextSync ( ) { const text = getTextSync ( ) ; this . feedback ( text ) ; } private feedback ( text ) { this . set ( "clipboardText" , text ) ; } }