locked
When To Use Angular Two Way Binding RRS feed

  • Question

  • User1928065626 posted


    Hi all,
    I have seen several tutorials on Angular two way binding but I still have a question about its use. In all of the tutorials on Angular two way binding, text entered into an input box are displayed else where on the page as they are being typed.

    The question I have is in what situation would I ever make use of this? Can someone please explain when I would want to use two way binding.

    Thursday, November 24, 2016 5:28 AM

Answers

  • User-707554951 posted

    Hi madjester,

    The question I have is in what situation would I ever make use of this? Can someone please explain when I would want to use two way binding.

    If you have the following two requirements

    1.When properties in the model get updated, so does the UI.

    2.When UI elements get updated, the changes get propagated back to the model.

    When data in the model changes, the view reflects the change, and when data in the view changes, the model is updated as well. This happens immediately and automatically, which makes sure that the model and the view is updated at all times.

    For example about this please refer to the following links:

    http://www.angularjshub.com/examples/basics/twowaydatabinding/

    http://jsfiddle.net/Xm5eH/9/

    Best regards

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 25, 2016 2:11 AM
  • User-474980206 posted

    you should probably ignore 2 way binding (it is often called an anti-pattern). The main goal of angular 2 was to replace 2 way binding with reactive binding (influence of reacts flux). see:

    http://blog.angular-university.io/functional-reactive-programming-for-angular-2-developers-rxjs-and-observables/

    or look at reactJS if you are not committed to angular.

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 4, 2016 8:37 PM

All replies

  • User-707554951 posted

    Hi madjester,

    The question I have is in what situation would I ever make use of this? Can someone please explain when I would want to use two way binding.

    If you have the following two requirements

    1.When properties in the model get updated, so does the UI.

    2.When UI elements get updated, the changes get propagated back to the model.

    When data in the model changes, the view reflects the change, and when data in the view changes, the model is updated as well. This happens immediately and automatically, which makes sure that the model and the view is updated at all times.

    For example about this please refer to the following links:

    http://www.angularjshub.com/examples/basics/twowaydatabinding/

    http://jsfiddle.net/Xm5eH/9/

    Best regards

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 25, 2016 2:11 AM
  • User-474980206 posted

    you should probably ignore 2 way binding (it is often called an anti-pattern). The main goal of angular 2 was to replace 2 way binding with reactive binding (influence of reacts flux). see:

    http://blog.angular-university.io/functional-reactive-programming-for-angular-2-developers-rxjs-and-observables/

    or look at reactJS if you are not committed to angular.

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 4, 2016 8:37 PM