HTML中的可观察状态未更新

时间:2019-04-09 14:15:05

标签: html typescript nativescript nfc

我正在开发具有nfc功能的应用程序。我在一开始就失败了。为了演示和测试Nfc-Tag,我想要一个按钮,该按钮将启动Ndef侦听器。当检测到标签时,标签应从“正在侦听...”更改为““读取:TagMessage”。只有在按其他键时才会显示。

我正在使用nativescript-nfc插件随附的demo-app,但我需要html页面而不是xml页面。我现在在网上搜索了一天,找不到任何有效的解决方案。

HTML代码:

any

TS代码:

--noImplicitAny

对于xml,该代码可以毫无抱怨地工作,有人可以告诉如何使其在html上实现吗?

编辑(使用NgZone):

<StackLayout>
    <Button text="Available?" (tap)="this.doCheckAvailable()"></Button>
    <Button text="Enabled?" (tap)="this.doCheckEnabled()"></Button>   
    <Button text="Start listening" (tap)="this.doStartNdefListener()"></Button>
    <Button text="Stop listening" (tap)="this.doStopNdefListener()"></Button>   
    <Label text="{{this.lastNdefDiscovered}}" textWrap="true"></Label>
</StackLayout>

进行此更改后,效果很好。

1 个答案:

答案 0 :(得分:0)

在html中删除this。 html文件的范围意味着您不需要使用this关键字,只需直接引用变量即可:

<StackLayout>
    <Button text="Available?" (tap)="doCheckAvailable()"></Button>
    <Button text="Enabled?" (tap)="doCheckEnabled()"></Button>   
    <Button text="Start listening" (tap)="doStartNdefListener()"></Button>
    <Button text="Stop listening" (tap)="doStopNdefListener()"></Button>   
    <Label text="{{lastNdefDiscovered}}" textWrap="true"></Label>
</StackLayout>
相关问题