Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
Loading js library fails

I have implemented a javascript library called Flickity and it works fine. But when I loop through a list of objects called from an api endpoint I get some errors.

The code I'm using is this:

<div class="main-carousel">

@foreach (var item in campaigns)
{
    <div class="carousel-cell"></div>
}
@code {
protected async override Task OnAfterRenderAsync(bool firstrender)
{
    if (firstrender)
    {
        await js.InvokeAsync<object>("initF");
    }
}

public List<StoreCampaignModel> campaigns { get; set; }

protected async override Task OnInitializedAsync()
{
    campaigns = await _repoCampaign.Get(EndPoints.StoreCampaignEndPoint + $"Get?orgId=11", Config.WebboxToken);
}

}

That renders the flickity object correctly but gives this error message in the console:

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at K10Forlag.UI.Shared.Flickity.BuildRenderTree(RenderTreeBuilder __builder) in C:\Users\peter\OneDrive\Websiter\Kanal10Media.UI\K10Forlag.UI\Shared\Flickity.razor:line 11 at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

So that means that campaigns is not initiiated so I'm thinking that I can either check if it's null or just initiate it as an empty list. But when I try that the javascript is not loaded correctly and the flickity object is not correctly shown.

I've included a little video to show the scenario. https://www.screencast.com/t/eksMC09oipJL

I'm not sure how to fix this but hope for help to a solution.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda