angularangular2-mdl

change ngModel value with checkbox


good day .. I have this code and I need to send the role..but when I select the checkbox the ngModel changes to True or False and it is what is sent to the DB..How can I solve it?

<mdl-checkbox class="mdl-textfield--full-width" *ngFor="let role of roles; let i = index"
[(ngModel)]="user.roles[i] " name="ckb{{i}}">
{{role.name}}
</mdl-checkbox>

Solution

  • May be you can set user roles in change event? Like (change)="userRoles[i] = role" A sample plunkr using Angular only:

    https://plnkr.co/edit/erIQNgk6u1JxOc6zCoHW?p=preview