0

I follow a lesson on nativescript and want to update the text in a LABEL (xml) with OBSERVABLE but my app crash.

xml:

<Page loaded = "mypageloaded">
    <StackLayout>
        <Button text="TAP" tap="onButtonTap" />
        <Label id = "lblcounter"  text="{{mylabel}}" />
    </StackLayout>
</Page>

js:

var observableModule = require("tns-core-modules/data/observable");

var counter = 42;
var page;

var user = new observableModule.fromObject({
  mylabel: "Test observable"
});

exports.mypageloaded = function (args) {
  page = args.objects;
  page.bindingContext = user;
};

exports.onButtonTap = function () {
  counter--;
  console.log(counter);
}

if I put the line PAGE.BINDINGCONTEXT in comment, no crash...and no update...

MikeP
  • 1
  • 1
  • `require` is a nodejs specific thing and is not natively supported in a web browser. You can read for alternatives [here](https://stackoverflow.com/a/4944920/3729184) – Omri Attiya Aug 17 '19 at 06:22

1 Answers1

0

It's typo, page = args.objects; suppose to be page = args.object;.

args is typeof EventData.

Manoj
  • 21,753
  • 3
  • 20
  • 41
  • Thanks Manoj. I had also to change the LABEL for TEXTFIELD in my xlm file. – MikeP Aug 17 '19 at 13:07
  • I don't know why you did that, may be if you wanted editable input. But it has nothing to do with crash or exception. – Manoj Aug 17 '19 at 13:08