C
C#4mo ago
jacks

blazor service issues

i'm trying to set a variable based on data inside of my service but it's not letting me do it unless it's inside of a method
No description
16 Replies
jacks
jacks4mo ago
and currently i can't call upon the method without getting errors so i'm not sure what to do
xyrile
xyrile4mo ago
why not put it on protected overried async Task OnInitializedAsync? to set the variable
Jimmacle
Jimmacle4mo ago
without knowing what the errors actually are we can't suggest much
jacks
jacks4mo ago
i'm unfamiliar
jacks
jacks4mo ago
No description
Jimmacle
Jimmacle4mo ago
there you go, you can't do that
jacks
jacks4mo ago
but how can i work around this
Jimmacle
Jimmacle4mo ago
do it in a method like xyrile suggested
jacks
jacks4mo ago
how would i do that in the way that he said to
Jimmacle
Jimmacle4mo ago
override that method and put your code in it
jacks
jacks4mo ago
yea but in this page? and how would i call the method?
jacks
jacks4mo ago
i tried calling the method like this
No description
jacks
jacks4mo ago
top one doesn't work bottom one is just error
Anu6is
Anu6is4mo ago
They said override on initialized It's called automatically when the component initialises You don't have to call it yourself, add the logic in there Just type override and space and the available methods should show
jacks
jacks4mo ago
okay i got it thank you
xyrile
xyrile4mo ago
Since you are unfamiliar with some of the life cycle of a razor you can check this out https://learn.microsoft.com/en-us/aspnet/core/blazor/components/lifecycle?view=aspnetcore-8.0
ASP.NET Core Razor component lifecycle
Learn about the ASP.NET Core Razor component lifecycle and how to use lifecycle events.