Angular2 two-way data binding

前端 未结 8 1836
谎友^
谎友^ 2020-12-15 05:10

I know Angular2 doesn\'t have two-way data binding but is there a way to mimick the two-way data binding behavior from Angular1.x?

8条回答
  •  别那么骄傲
    2020-12-15 05:41

    From the Docs:

    Two-way binding ( [(...)] )

    You often want to both display a data property and update that property when the user makes changes.

    On the element side that takes a combination of setting a specific element property and listening for an element change event.

    Angular offers a special two-way data binding syntax for this purpose, [(x)]. The [(x)] syntax combines the brackets of property binding, [x], with the parentheses of event binding, (x).

    [( )] = BANANA IN A BOX
    

    Visualize a banana in a box to remember that the parentheses go inside the brackets.

    For more information, see

    • Angular Developer Guide - Template Syntax - Two-way binding
    • Angular @angular/forms API Reference - ngModel Directive

提交回复
热议问题