Skip to content

using ObserverService throws an exception #50

@EnjoyMachine

Description

@EnjoyMachine

Hi

I have a loader at the end of the page.
When the user scrolls to to the end of the page, I want the loader to no more observe untill new data is loaded.
And observe again once new data loaded.
Here is my code:

public async Task SetupObserver()
{
   endOfListObserver = await ObserverService.Create(async (entries) => {
    IsIntersecting = entries.FirstOrDefault().IsIntersecting;
    Console.WriteLine("IsIntersecting...");
    if (!IsLoading)
    {
      if (IsIntersecting)
      {
        await endOfListObserver.Unobserve(LoaderElement);
        Console.WriteLine("unobserve");
        var canAddMore = await LoadData();
        StateHasChanged();
        if (canAddMore)
        {
          await endOfListObserver.Observe(LoaderElement);
          Console.WriteLine("observe");
        }
      }
    }   
  });

  await endOfListObserver.Observe(LoaderElement);
}

html code is just

 <span @ref="LoaderElement">Please wait</span>

But an error is throwned when trying to unobserve :
Microsoft.JSInterop.JSException : 'An exception occurred executing JS interop: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4.. See InnerException for more details.'
InvalidOperationException : Cannot get the value of a token type 'Null' as a boolean.

Any idea ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions