Angular2 two-way data binding

前端 未结 8 1837
谎友^
谎友^ 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:36

    Here is a simple plunker which demonstrates one way, two way and event driven approaches in action according to Angular2 2.0.0-beta.17

    http://plnkr.co/eXZMoU

    Two-way Event and property

    
    

    One way property

    
    

    Event driven

    
    

    We can dig Angular docs for more

    [UPDATE 1/26/2020]

    Since Angular2 beta libs are removed from project CDN ! above plnkr link doesn't work anymore.

    Use below new plnkr Angular 6+ page , I ported previous page to NPMJS, new angular edition and new plnkr!

    http://next.plnkr.co/edit/4okdOSgw3SMvdktR?preview

提交回复
热议问题