jcadafalch / TaskManager

MIT License
0 stars 0 forks source link

B.A Implement ListarEtiqueta.razor #10

Closed jcadafalch closed 2 years ago

jcadafalch commented 2 years ago

En intentar mostrar les etiquetes, salta el següent error per consola:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Value cannot be null. (Parameter 'client')
System.ArgumentNullException: Value cannot be null. (Parameter 'client')
   at System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync[EtiquetaDTO[]](HttpClient client, String requestUri, JsonSerializerOptions options, CancellationToken cancellationToken)
   at System.Net.Http.Json.HttpClientJsonExtensions.GetFromJsonAsync[EtiquetaDTO[]](HttpClient client, String requestUri, CancellationToken cancellationToken)
   at GestorTareas.Client.Pages.Etiqueta.ListarEtiquetas.CargarEtiquetasAsync() in C:\Users\j.cadafalch\Documents\GitHub\GestorTareas\GestorTareas\Client\Pages\Etiqueta\ListarEtiquetas.razor.cs:line 14
   at GestorTareas.Client.Pages.Etiqueta.ListarEtiquetas.OnAfterRenderAsync(Boolean firstRender) in C:\Users\j.cadafalch\Documents\GitHub\GestorTareas\GestorTareas\Client\Pages\Etiqueta\ListarEtiquetas.razor.cs:line 22
easis commented 2 years ago

Els 3 errors (#4, #5, #6) són el mateix, no estàs injectant bé les dependencies.

Injectar un servei a un component:

@inject HttpClient Http

Injectar un servei a un component (code behind):

using Microsoft.AspNetCore.Components;

partial class NomComponent
{
    ...
    [Inject] protected HttpClient Http { get; set; } = default!;
    ...
}

Documentació: https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-6.0#request-a-service-in-a-component

jcadafalch commented 2 years ago

done and pushed