vendredi 1 juillet 2016

angular 2 - checkbox "checked" depend on function not on property biind

I have a checkbox that needs to be shown as selected depending on a function result instead of binding it to an object property.

This would be easy, but is not possible:

<input type="checkbox" ([ngModel])="category.selected">

And this does not work, as even checked="false" results in a checkbox being displshownayed as selected:

<input type="checkbox" [attr.checked]="isCategorySelected(category.id)"/>

I need an outcome like this

<input type="checkbox">
<input type="checkbox" checked>

depending on the result isCategorySelected(id).

Any help is appreciated.




Aucun commentaire:

Enregistrer un commentaire