Last active
November 15, 2022 03:04
-
-
Save scottsauber/d7a8fa57cd517febbc92b5db214a3149 to your computer and use it in GitHub Desktop.
bind-value-oninput example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/" | |
<input @bind="SearchTerm" @bind:event="oninput" /> | |
<span class="text-muted ml-5"> | |
Showing @FilteredToDos.Count out of @ToDoItems.Count | |
</span> | |
<h4 class="mt-4">To Do's</h4> | |
<ul> | |
@foreach (var toDo in FilteredToDos) | |
{ | |
<li>@toDo.Name</li> | |
} | |
</ul> | |
@code { | |
// Initialize SearchTerm to "" to prevent null's | |
string SearchTerm { get; set; } = ""; | |
// Imagine this was retrieved from an API, just hardcoding for demo purposes | |
List<ToDoItem> ToDoItems => new List<ToDoItem> | |
{ | |
new ToDoItem { Name = "Garbage" }, | |
new ToDoItem { Name = "Dishes" }, | |
new ToDoItem { Name = "Wash clothes" }, | |
new ToDoItem { Name = "Water flowers" } | |
}; | |
List<ToDoItem> FilteredToDos => ToDoItems.Where(i => i.Name.ToLower().Contains(SearchTerm.ToLower())).ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment