【发布时间】:2018-08-05 03:10:58
【问题描述】:
以下模型工作正常,我有一个 prent 组件 (app.html + .ts) 一个子组件 (test-binding.html + .ts) 和一个双向绑定的输入字段
父组件
<template bindable="query">
<require from="./test-bindable"></require>
<input type="text" value.bind="query"/>
<test-bindable query.bind="query"></test-bindable>
</template>
test-bindable.html
<template>
<div>${query}</div>
</template>
test-bindable.ts
import { bindable } from 'aurelia-framework';
export class TestBindable{
@bindable query = 'potato';
valueChange(newValue, oldValue)
{
//Do something
}
created(){
console.log('test component created');
}
}
但是,我不确定如何使用 2 个子自定义组件实现相同的功能。我可以使用eventAggregator 轻松实现相同的目的,并在我的子组件中侦听要触发的事件,但是,我正在尝试使用两种方式绑定来实现相同的功能。例如:
父组件(app.html)
<template bindable="query">
<require from="./test-bindable"></require>
<require from="./test-input"></require>
<test-input value.bind="query"></test-bindable>
<test-bindable query.bind="query"></test-bindable>
</template>
测试输入.html
<template>
input type="text" value.bind="test"/>
</template>
测试输入.ts
import { bindable } from 'aurelia-framework';
export class TestInput{
@bindable query;
valueChange(newValue, oldValue)
{
//Do something
}
created(){
console.log('test component created');
}
}
【问题讨论】:
标签: typescript aurelia two-way-binding