I can't figure out how to implement React-style controlled components in Angular. The behavior I'm trying to implement is related to mat-select, but this seems to work the same way with regular selects as well. So here's what I'd like to achieve:
- the select receives it's value via an input
- when the select changes, the parent component will receive the change and handle it. It's the parent's business how it handles the change.
- if the parent does not change the value of the input, I would like the select to still display the initial value, despite the user's attempted change
This is trivial to implement in React, as it is the default behavior for any sort of input. I tried to achieve a similar behavior in Angular using [ngModel] along with (ngModelChange), but it seems I'm doing it wrong.
It might seem like it's a weird behavior to ask for, but that's not the case: the selection change might trigger an async action that might succeed or fail, so it would make sense that in case of failure the value would not change. Here's an example: the update will fail half the time; when it does, the value stays the same, otherwise it changes to the new value.