Accepted answer


when angular sets up databinding two "watchers" exist (this is a simplification)

$ = 'test';
$timeout(function()  { $ = 'another' }, 1000);
$timeout(function()  { console.log($; }, 5000);

<!-- html --->
<input ng-model="name" />

the input will start out with test, then update to another in 1000ms. any changes to $, either from controller code or by changing the input, will be reflected in the console log 4000ms later. changes to the <input /> are reflected in the $ property automatically, since ng-model sets up watches the input and notifies $scope of the changes. changes from the code and changes from the html are two-way binding. (check out this fiddle)


react doesn't have a mechanism to allow the html to change the component. the html can only raise events that the component responds to. the typical example is by using onchange.

render() { 
    return <input value={this.state.value} onchange={this.handlechange} />
handlechange(e) {

the value of the <input /> is controlled entirely by the render function. the only way to update this value is from the component itself, which is done by attaching an onchange event to the <input /> which sets this.state.value to with the react component method setstate. the <input /> does not have direct access to the components state, and so it cannot make changes. this is one-way binding. (check out this codepen)


one way data binding is very simple, except in react we rarely use the word binding to refer how the data flows.

  const fn = (a) => { return ... }

if a value is provided as a, we'll use that value in the function scope. the above is programming 101.

  <title name={"hello"} />

the above line doesn't mean anything would magically happen other than the fact that "hello" is sent to title function and set one prop to "hello", if you insist to use the word bind here, that's where the bind happens.

whether you want to use this prop to display or wire with another state or whatever, you have to code yourself! there's no other magic. btw, this is called props in react. and props is more or less a function's input argument coded in an object format. so the more accurate definition of this "bind" in react should be called assignment. in react source code, you'll see something very quickly after the element is created.

  element.props = { name: "hello" }

and believe it or not, there's no other code in react that does anything to do with this "bind" later on.


use the input example,

<input value={value} onchange={onchange} />

if we give a value to input, the input would pick up the value to display it. if you change the value, you are intending to change the display.

why does the value change? it can't by default. you have to change it by either listening to a system event like onchange or some business logic like settimeout or whatever way you can ever imagine. but the change is an action, you perform the action therefore you can handle the action by changing the value. i guess this is where the "one-way" comes from. essentially nothing is free.


what gets us confused is that dom element has its own state or properties. for example, we can do el.textcontent="abc" without using react.

<input />

if we just code like this, we still see the value on screen changes after we type in anything. but this behavior has nothing to do with react, it's the dom element functionalities. react refers to the first version as controlled element. essentially react overwrites the dom way.


to be honest, only after i stopped using the word "binding" for these cases, i started to understand what they are. but that could be just me.


what is data binding?

data binding is a general technique that binds data sources from the provider and consumer together and synchronizes them.

data biding in angular

according to angularjs documents, data-binding in angularjs apps is the automatic synchronization of data between the model and view components. the view is a projection of the model at all times. when the model changes, the view reflects the change, and vice versa

enter image description here

the template (which is the uncompiled html along with any additional markup or directives) is compiled on the browser. the compilation step produces a live view. any changes to the view are immediately reflected in the model, and any changes in the model are propagated to the view.

data binding in reactjs

the connection between the data to be displayed in the view and the component’s logic is called data binding in reactjs. reactjs uses one-way data binding. in one-way data binding one of the following conditions can be followed:

  • component to view: any change in component data would get reflected in the view.
  • view to component: any change in view would get reflected in the component’s data.

enter image description here

read more here and here.


two-way data binding provides the ability to take the value of a property and display it on the view while also having an input to automatically update the value in the model. you could, for example, show the property "task" on the view and bind the textbox value to that same property. so, if the user updates the value of the textbox the view will automatically update and the value of this parameter will also be updated in the controller. in contrast, one way binding only binds the value of the model to the view and does not have an additional watcher to determine if the value in the view has been changed by the user.

regarding react.js, it was not really designed for two way data binding, however, you can still implement two-way binding manually by adding some additional logic, see for example this link. in angular.js two-way binding is a first class citizen, so there is no need to add this additional logic.


i made a little drawing. i hope it's clear enough. let me know if it's not !

2 ways data binding vs 1 way data binding

Related Query

More Query from same tag