This code will help you to understand how to conditionally add Blazor components’ template.
The if the statement is used to display a component or fragment conditionally. If the condition evaluates to true, the component will be loaded to the view.
Whenever the properties used in the if statement change
<button class="btn" @onclick="ButtonClicked">Show</button> @if (ShowComponent) { <FetchData></FetchData> } @code{ public bool ShowComponent { get; set; } public void ButtonClicked(MouseEventArgs e) { ShowComponent = true; } }
, the condition evaluates to either true or false and adds or removes the component to the page.
Refer to the following code sample.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
The if the statement is used to display a component or fragment conditionally. If the condition evaluates to true, the component will be loaded to the view.
Whenever the properties used in the if statement change
, the condition evaluates to either true or false and adds or removes the component to the page.
Refer to the following code sample.
need an explanation for this answer? contact us directly to get an explanation for this answer