Search code examples
typescriptnativescript

How to call a function from Textchange event in typescript/nativescript


I'm trying to call a function to update a variable based on TextField input.

I may be missing something in the documents, but I can't figure this out.

This is my XML

    <StackLayout class="p-20">
    <Label text="{{_message}}" class="h2 text-center" textWrap="true" />
    <TextField text="target" hint="Target" textChange="updateTarget" />
    
</StackLayout>

This is the main-view-model.ts

  updateTarget(_target: string) {
      console.log("Updating target: ${this._target}")
      this.message = `Target: ${this._target}`
    }

The updateTarget function isn't being called at all, I've tried extensive googling, but nothing seems to work.


Solution

  •     <TextField text="target" hint="Target" textChange="{{updateTarget}}" />