Nativescript模式按钮点击事件不起作用

时间:2017-12-07 20:12:50

标签: javascript xml typescript nativescript

我可以在main.xml上显示自定义模式。它包含两个用于添加图像或录制音频的按钮。

我的问题:当打开模态并点击它们时,我无法使这些按钮点击事件。 console.log应显示"添加图像"或"录制音频"。

主要-page.xml

<FAB:fab row="1" tap="{{ openModal }}" icon="res://add_white" rippleColor="#f56c0a" class="fab-button" horizontalAlignment="right" />

main.ts

import {Observable} from 'data/observable';
import { Page } from "ui/page";

export class AssistenceViewModel extends Observable {

constructor() {
    super();
   }

public openModal() {
    console.log("fab tap");

    var modalPage = "./modal/modal-page";
    var context = "contexto";
    var fullscreen = false;

    const page = <Page>args.object.page;

    page.showModal(modalPage, context, function(){
        //code...
    }, fullscreen);
}  

模态-page.xml

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">

<StackLayout class="p-16">

    <Label text="Opções" horizontalAlignment="center" textWrap="true" />

    <Button class="btn mybtn" text="Adicionar Imagem" tap="{{ addImage }}"></Button>
    <Button class="btn mybtn" text="Gravar Áudio" tap="{{ addAudio }}"></Button>

  </StackLayout>

</Page>

modal.ts

import {Observable} from 'data/observable';

export class ModalViewModel extends Observable {

constructor(){
    super();
}

public addImage(){
    console.log("add images"); // it doesn't work
}

public addAudio(){
    console.log("record audio");  // it doesn't work
}

}

0 个答案:

没有答案