1

So I'm just trying to save values from textfields to variables javascript.
I'm seeing that I should do something like this from another post

var view = require("ui/core/view");
function pageLoaded(args) {
    var page = args.object;
    var textfield= view.getViewById(page, "textfieldID");
}

however, I do not really understand how exactly I should be using it. where do I call pageloaded and what arguments?

coderman401
  • 582
  • 3
  • 17
ZoomerCoder
  • 5
  • 1
  • 3
  • While using Angular, you may not really do `document.getElementByID(...)`. Use ViewChild to access element from your template. If you just want to access the values, you may stick to ngModel like @coderman said. – Manoj Feb 15 '20 at 08:38

1 Answers1

2

In nativescript angular,

We have to use two data biding for this.

in your component.html file :

<TextField
    hint="username" 
    [(ngModel)]='username'>
</TextField>

in your component.ts file declare the variable username: string = '';

the [(ngModel)] is used for two way data binding so you can access the value from your textfield.

but take a note that you have to import NativeScriptFormsModule in import:[] array of your module file in order to use two way data binding.

coderman401
  • 582
  • 3
  • 17