We have a form in an Angular 2 app. The form has a checkbox. Under some circumstances, checking the checkbox is illegal. When the user checks the checkbox, we want to show an error message and uncheck the checkbox.
This almost works. In our event handler we check the condition, warn the user and set the checkbox variable back to false. Unfortunately, the checkbox remains checked.
The order of events as we have seen it is this:
- User clicks the checkbox.
- Our
checkboxvariable becomes true. - Our event handler is called.
- Alert is shown (using
alertfor now) - Alert is dismissed
checkboxvariable set to false by our code.- Our event handler finished.
Checkbox is checked in the browser
The model (
checkbox) remains false, but the user doesn't see it. How can I uncheck the checkbox after it is actually checked (as opposed to 'about-to-be-checked')?Here is a Plunkr demonstrating the issue.