I have two ways of running function in my Blazor app.
- <h1 @onchange="e => action(message)">@message</h1>
- <button @onclick="e => action(message)">Click</button>
The first code line should work on change meanwhile the second works on click. I cannot find out why the first one is not working. My program logic is as follows:
- @code {
- GameManager _gameM;
- public string message { get; set; } = "test";
- protected override void OnInitialized()
- {
- _gameM = new GameManager();
- _gameM.MainLoopCompleted += (e, o) => StateHasChanged();
- _gameM.MainLoopCompleted += (e, o) => special();
- }
- public async Task action(string message)
- {
- var confirmed = await js.InvokeAsync<bool>("confirm", $"{message}");
- if(confirmed)
- {
- Console.WriteLine("working");
- }
- }
- public void special()
- {
- message = _gameM.message;
- }
- }
In this code I have a line:
- _gameM.MainLoopCompleted += (e, o) => special();
Which for sure changes @message inside <h1>, however, the function action() is not triggered by this change. Why is it so and how to solve it?