0

I am trying to get a checkbox checked if the object I send in the model has a particular attribute set to true (in this case mentor).

<label th:text="Mentor">Mentor </label>:<span th:text="${useraux.mentor}"/>
        <input type="checkbox" th:checked="${useraux.mentor}" th:field="${useraux.mentor}" ng-model="mentor"></input>

I know it is true, because it gives me this output. enter image description here But it does not activate the checkbox, I have tried many ways and I am not able to get it checked.

jack nieve
  • 21
  • 3
  • I see `ng-model` on there, is that angular? you just need to add the `checked` attribute to the input. – Chris W. Apr 19 '22 at 19:28
  • There I use angular so that if it is checked, extra fields appear. Even if I add checked to the input it does not change anything. – jack nieve Apr 19 '22 at 20:02
  • 2
    If you have the attribute on there like `` or `checked="true"` it should display as checked. If not, there's something else interfering like CSS or an attribute change or something somewhere, would need a reproducible example to troubleshoot it though. – Chris W. Apr 19 '22 at 20:10
  • Remove the ngModel=.... thing which seems like angular, which works on client side modification. Remove it temporarily, check it works or not. – Ratul Sharker Apr 24 '22 at 17:53

1 Answers1

0

I believe you want to set a condition on checked, if it comes as true you want the checkbox to be checked. Just set a condition on the property checked in your input, like this:

TS:

export class AppComponent {
  isChecked = 'thisTrue';
}

HTML:

<input type="checkbox" [checked]="isChecked == 'thisTrue'" /> //this will be checked
<input type="checkbox" [checked]="isChecked == 'no'" /> //this wont be checked
manjiro sano
  • 784
  • 3
  • 15