Web Developer

Section 2-4 Data binding

  1. String Interpolation: {{data}}
  2. Property Binding: [property]=”data”
  3. Event Binding: (event)=”expression”
  4. Two-Way-Binding: [(ngModel)]=”data”

String Interpolation: {{data}}, in double curly brace, you can use property, expression that will return a string, or method that return string. Remember, in in double curly brace, you can use anything that return a string or can be converted into a string, however, you can’t use if or for statement, or multiline string.

Property Binding: [property]=”data”, all these are base on the element instantiated from the Class, and the data is defined in the class.

Event Binding: (event)=”callback function”

Two-Way-Binding: [(ngModel)]=”data”, this will immediately change data value

Very important tips: for data bingding, angular will evaluate the code between quotation marker as typescript code, so you can write any JS code between ” “, such as variablename === sth, which will be determined true or false.

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>