在react中创建一个父/子组件,该组件具有绑定到子组件的一些附加方法,我有如下内容
<RadioGroup
{...args}
value={value}
onChange={(name, value) => setValue(value)}
>
<Radio value="apple">apple</Radio>
<Radio value="orange">orange</Radio>
<Radio value="banana">banana</Radio>
</RadioGroup>
const key = `${name}-${child.props.value}`;
const _name = `${name}-${Date.now()}`;
return React.cloneElement(child, {
...childAttrs,
name: _name,
checked: child.props.value === value,
onChange: onChangeHandler,
key,
});
Angular组件将以类似的方式构建
<my-radio-group
[name]="name"
[disabled]="disabled"
(selectionChange)="selectionChange($event)"
[orientation]="orientation"
>
<my-radio [value]="'apple'">apple</my-radio>
<my-radio [value]="'orange'">orange</my-radio>
<my-radio [value]="'banana'">banana</my-radio>
</my-radio-group>
向Angular中的子组件添加类似“onChange”的处理程序的最佳和最简单方法是什么?在没有RxJ和订阅的情况下可以做到这一点吗?