プラグインのコードの論理的な流れに本当に混乱しました。私は私が持っている、このseedを使用していますが、ちょうどにconsole.logが含まれているプラグインから関数を呼び出すデモアプリケーション、中にボタンを作成しようとしています:私のXMLでNativescriptのボタンタップからプラグイン関数を参照する
//yourPlugin.common.ts:
import * as app from 'application';
import * as dialogs from 'ui/dialogs';
export class Common {
public message: string;
constructor() {
this.message = Utils.SUCCESS_MSG();
}
}
export class Utils {
//Utils Stuff - not relevant for this issue
}
export function Click() {
console.log("Clicked");
}
//demo/app/main-view-model.ts:
import {Observable} from 'data/observable';
import {YourPlugin} from 'nativescript-yourplugin';
export class HelloWorldModel extends Observable {
public message: string;
private yourPlugin: YourPlugin;
private Click: YourPlugin.Click;
constructor() {
super();
this.yourPlugin = new YourPlugin();
this.message = this.yourPlugin.message;
}
}
、その後に、私が追加しましたアプリのページへ<Button text="This is Button!" tap="Click" />
しかし、私がボタンを押すと、コンソールログが起動していない、何が間違っていますか?
更新:
のxml:
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded">
<StackLayout>
<Label text="{{ message }}" class="message" textWrap="true"/>
<Button text="This is Button!" tap="{{ Click }}" />
</StackLayout>
</Page>
メインpage.ts:
import * as observable from 'data/observable';
import * as pages from 'ui/page';
import {HelloWorldModel} from './main-view-model';
// Event handler for Page "loaded" event attached in main-page.xml
export function pageLoaded(args: observable.EventData) {
// Get the event sender
var page = <pages.Page>args.object;
page.bindingContext = new HelloWorldModel();
}
私はあなたの正確なコードをコピーした場合、+輸入:あなたはこのようになっているはずです
HelloWorldModel
あなたのボタンのインスタンスにあなたのXMLを結合していると仮定すると、最終的そして:だからあなたのコードは次のようになりますこのプラグインは 'natives-nsplugin'のnsPluginとしてインポートしています; 'まだボタンプレスでconsole.logを取得できません... –