ボタン#btn1
または#btn2
保存をクリックすると、コンソールに次のように表示されます。
Uncaught Error: save is not a function
getFunction @ aurelia-binding.js:1971
evaluate @ aurelia-binding.js:1565
callSource @ aurelia-binding.js:4989
(anonymous function) @ aurelia-binding.js:5013
handleDelegatedEvent @ aurelia-binding.js:3211
しかし、外側のボタンは正常に機能します#btn3
。私も試し$parent.save()
てみ#btn2
ますが、うまくいきません。何か案が?
app.html
<create-location contact.two-way="contact" working-time.two-way="workingTime">
<require from="dist/component/working-time"></require>
<working-time title="Working Time" view-model.ref="workingTime"></working-time>
<require from="dist/component/contact"></require>
<contact title="Contact" phone="123" email="user@example.com" fax="123456" view-model.ref="contact"></contact>
<button id="btn1" type="button" click.delegate="save()">Save (=>error<=)</button>
<button id="btn2" type="button" click.delegate="$parent.save()">Save (=>error also<=)</button>
</create-location>
create-location.html
<template>
<button id="btn3" type="button" click.delegate="save()">Save (=>it works<=)</button>
<content></content>
</template>
create-location.js
import {bindable} from 'aurelia-framework'
export class CreateLocationCustomElement {
@bindable contact;
@bindable workingTime;
save() {
alert("save");
}
}
更新 Fabio の提案を試してみましたが、うまくいきました。
別の質問: aurelia dialogを見てください。私の場合と同様に、要素testDelegate
内のビューモデルの関数を呼び出します。<content>
彼らは使用しませんview-model.ref
。ソースコードを見てみましたが、その呼び出しをどこで処理しているのかわかりません。たぶん、私はいくつかの点を見逃しているか、ここに慣例があります。彼らがそれをどのように行うか知っている人はいますか?