I have two html components - an <input type="text"/> and a <label/>. The goal is to have the value of the label update with each keystroke of the textbox.
The text input is setup like this:
<input type="text" @bind="@SelectedField.Name"/>The behavior that I'm seeing is the value of the text-input isn't propagating to SelectedField.Name with each keystroke. I setup an @onKeyUp event to check this. Entering values into the text-input isn't updating the value of SelectedField.Name until after the text-input is destroyed.
This implementation is in .NET 7.
How I tested this:
<input type="text" @bind="@SelectedField.Name" @onkeyup="() => CheckData()"/>@code { public void CheckData() { Console.WriteLine(SelectedField.Name); }}- The initial value of
SelectedField.NameisString.Empty - Expected behavior is that on every key-press, the value of the
text-inputis printed to the console. - Actual behavior is that on every key-press, an empty string is printed to the console.
Is this a bug? Am I using the @bind functionality incorrectly? I'm coming from Angular so maybe I'm looking at this with the wrong pattern.