1

I have a single page blazor application,where I have a dynamic component tag

  @page "/"

  @if (_loadSettingCompleted)
 {
 <HeaderNavMenu SelectDialog="OnSelectDialog" 
 ReloadSettings="OnReloadSettings"/>
 <div class="d-flex flex-column" style="min-height: 100%; 
 position:relative;">
    <DialogProvider />
          
<DynamicComponentType="_bfMainPageComponentService.Type"/>
    <BfMessageDialogProvider />
    
</div>

<MonitorActivity />
<TokenRefresher />
<PrintedReportProvider />
<ReportLoaderProvider />
 }

which supposed to display some content.I also have injected service

    [Inject]
    private IBfMainPageComponentService _bfMainPageComponentService { get; set; }

with “_type” property,which is equal to the Type of dynamicComponent and a method which changes “_type” to the parameter of the method.

     public class BfMainPageComponentService : IBfMainPageComponentService
     {
       public Type _type { get; set; } = typeof(CurrencyRatesViewer);

    public void MainPageComponentChanged(Type type)
    {
        if (type != null)
        {
            _type = type;
        }
    }
}

Whenever I try to change _type in some other place by injecting a service and passing different type, it changes the old content with the new one as it should, however, it displays the new component twice. Seems that it changes the type of the component, but also creates a new one with that type. How can i somehow close the old component and show just 1? Best regards, Kadyrbek

0 Answers0