gpt4 book ai didi

javascript - 到 ngReact 组件的双向数据绑定(bind)

转载 作者:可可西里 更新时间:2023-11-01 01:53:36 24 4
gpt4 key购买 nike

如何使用 ngReact 优雅地设置双向数据绑定(bind)?

假设我有一个简单的 React 输入组件,它接受一个 value 并触发 onChange:

angular.module('app', []).value('SimpleInput', props => 
<input type='text'
value={props.value}
onChange{e => props.onChange(e.target.value)} />
)

然后从 AngularJS 方面来看,我希望像这样的东西来更新作用域中的 value:

<react-component name="SimpleInput" 
props="{value: value, onChange: v => value = v}">
</react-component>

但是,是否有更优雅的方式来设置到 AngularJS 作用域的双向绑定(bind),类似于 ng-model

最佳答案

我不这么认为。 ngReact 只是一种将 React 组件注入(inject) Angular 框架的方法; React 专门设计为不支持性能的双向数据绑定(bind),因此任何实现都必然是一种变通方法。

出自马口:

ngReact is an Angular module that allows React Components to be used in AngularJS applications. Motivation for this could be any of the following: You need greater performance than Angular can offer (two way data binding, Object.observe, too many scope watchers on the page) ...

关于javascript - 到 ngReact 组件的双向数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31329592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com