I have read an article about difference between property and attribute bindings. From what I understood, most of the time, Angular2 prefers property bindings,
because after each change in data, the DOM would be updated. (If I am mistaken, please correct me).
I have a custom component and use it from the parent component. In it, I have an @Input
named truevalue
. when I initiate truevalue
from the parent via property binding, sometimes, it does not change. I used following code:
<my-checkbox [(ngModel)]="chkItems" [disabled]="!editMode" [trueValue]="Y"></my-checkbox>
If I send true
or "1"
into trueValue
it works, but If I send "Y"
or "YES"
, it does not work. So I am forced to use attribute binding. I don't know what is the problem.
I have changed it, into the following:
<my-checkbox [(ngModel)]="chkItems" [disabled]="!editMode" trueValue="Y"></my-checkbox>
Thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…