Attribute vs property
Example: <input type=”text” value=”Biswas”>
- Attribute and property not the same
- Attribute defined by HTML
- Properties – Defined by DOM (Document Object Model)
- Attributes initialized by DOM properties and they are done. Attributes value cannot change once they are initialized.
- Property values however can change.
- HTML attribute value specifice the initialize value. And DOM value is the current value
- Property binding actually binding DOM element
Into component:
public myId = “testId”;
<input [id]=”myId” type=”text” value=”Biswas”>
So we are binding myId property of this input element (id is a attribute)
# another way to bind using interpolation
<input id=”{{myId}}” type=”text” value=”Biswas”>
# way to bind
<input [disabled]=”isDisabled” id=”{{myId}}” type=”text” value=”Biswas”>
TS file:
public isDisabled = true;
# way to bind
<input bind-disabled=”isDisabled” id=”{{myId}}” type=”text” value=”Biswas”>
Why need property binding:
- Interpolation only work string value for binding
- Interpolation doesn’t work when boolean using.
- Example: <input disabled=”false” id=”{{myId}}” type=”text” value=”Biswas”>
- <input disabled=”{{false}}” id=”{{myId}}” type=”text” value=”Biswas”>