locked
Get ref to element inside an if RRS feed

  • Question

  • User-336073119 posted

    Hi, it looks like @ref are not set on components inside conditionals. i.e.

    @if (null == @_SelectedTypeMap)
                {
                            <MudText>@_L["msg_NothingSelected"]</MudText>
                }
                else
                {
                    <MudTable @ref=RecTypeTable ServerData="@(new Func<TableState, Task<TableData<RecordTypeDTO>>>(GetTypesForMap))" Dense="true" >

    then the ref to the table is never set, however I need it to enable loading of data. Is there something I am missing about using ref?

    Wednesday, December 30, 2020 5:22 PM

Answers

  • User-336073119 posted

    It looks like it an issue with the MudTable, not loading the data, the place I was trying to access the ref was before in the FN that set the SelectedTypeMap, so at that point the ref should be null, it is however set on a 2nd selection. Had to dig a bit deeper as not obvious from first error of null exception.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 30, 2020 8:45 PM

All replies

  • User475983607 posted

    The code runs when the component initially loads.  I'm not sure if your design works since you only posted the condition but I think both component should be loaded.  Then just toggle visibility.  

    Wednesday, December 30, 2020 8:42 PM
  • User-336073119 posted

    It looks like it an issue with the MudTable, not loading the data, the place I was trying to access the ref was before in the FN that set the SelectedTypeMap, so at that point the ref should be null, it is however set on a 2nd selection. Had to dig a bit deeper as not obvious from first error of null exception.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 30, 2020 8:45 PM