Search code examples
angulartypescriptngforangular-ng-if

change text label after checkbox is checked angular


Using this tutorial dynamic checkbox angular, I have create dynamic checkboxes and I need to change the text label after the the checkbox was checked. But I can't solve the problem where i need text label change on checked selected index only, for now it changes all the text. This is what i had tried so far: demo,

this is what I want to produce,

Before checked:

  • select (ticked checkbox)
  • select
  • select
  • select

After checked:

  • selected (change text label)
  • select
  • select
  • select

Solution

  • You are using one variable marked to change the text of all the labels.

    You should use value of each control to change it like the following code.

    <span *ngIf="order.value">
      {{orders[i].text2}}
    </span>
    <span *ngIf="!order.value">
      {{orders[i].text1}}
    </span>