Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Databinding in Angular 2

Databinding in Angular 2

Manfred Steyer

October 25, 2016
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. About me … • Manfred Steyer • SOFTWAREarchitekt.at • Trainer

    & Consultant • GDE and MVP • Focus: Angular Page  2 Manfred Steyer
  2. Data Binding in AngularJS 1.x Page  4 Model Model

    Directive Nearly everything can depend on everything Leads to serveral digest cycles
  3. Angular 2 Page  5 Component for whole App Component

    (e. g. list) Component (e. g. list-item) Component (e. g. list-item)
  4. Property Binding (One Way, Top/Down) Page  6 model item

    item {{ item.title }} {{ item.title }} [http://victorsavkin.com/post/110170125256/change-detection-in-angular-2]
  5. Property Binding (One Way, Top/Down) • Only one digest cycle

    needed • Child component must not modify parent component (e. g. by using setters) • Angular 2 checks for this in dev mode
  6. Event Bindings (One Way, Bottom/Up) Page  8 {{ item.title

    }} {{ item.title }} Event-Handler Event-Handler
  7. Event Bindings (One Way, Bottom/Up) • No digest cycle for

    propagating events • But: Events can change state  Updating Property Bindings Page  9
  8. Property and Event Bindings Page  10 Performing Property Bindings

    Executing Event Handlers Event occurs App is ready All handlers executed Properties bound
  9. Two Way = Property and Event Bindings Page  12

    <input [ngModel]="from" (ngModelChange)="from = $event"> Property + Change changed value
  10. Summary • Property Binding: One Way; Top/Down • Event Binding:

    One Way; Bottom/Up • Two Way = Property Binding + Event Binding • Conventions for Two Way Binding • Align to this conventions in own components Page  13