Closed dlr1 closed 4 years ago
Please see Component Attributes on this page for information on the supported syntax: https://blazor.net/docs/components/index.html
Also the following post might be helpful: https://github.com/aspnet/Blazor/issues/743#issuecomment-386548638
Just to clarify, I am not talking about the values not being updated.
The scenario is.
The Gist of what I am trying to do is, have a bunch of parameters set on a component and then call a method in the component to draw the chart. what I see happening is even though the parameter value in the component is updated, the value of that in the method doesn't reflect the same value.
Blazor doesn't know you've changed the state inside mycomp
unless it calls StateHasChanged
.
StateHasChanged has no effect
Oh I see. You're calling MyMethod
before the component has rendered, and hence it has not yet received an updated [Parameter]
value.
These kinds of ordering dependencies are one of the reasons why it's recommended to use declarative methods for passing data, rather than procedural ones via ref
and calling methods. Where possible, don't call methods on child components. Just update the parameters you're passing to them. The child component can react to updated incoming values by overriding OnParametersSet
/OnParametersSetAsync
if you need.
It works if I use OnParametersSet, I assumed when I change the parameter value it is reflected immediately. I understand now. Thanks
I have a component("mycomp"). I am just writing the value of parameter and expect the values to be in sync. what am I missing?
I am using the above component in another page like below