i'm trying to re-create the TodoMvc app in Angular2 .
I'm struggling with filtering the list based off a click event. Codesandbox here
The flow is as follows:
this.todoItemFilter = TodoItemFilter.All
and *ngFor="let item of todoItems | filter: filterTodoItems"
All/Active/Completed
results in a function call setSelectedFilter(todoItemFilterEnum.All)
which updates the filter property this.todoItemFilter = filter;
but view is not re-rendered.I'm pretty sure there are multiple ways to solve this problem i'm actually interesting in as many as possible thank you!
You can set a new reference to todoItems:
setSelectedFilter(filter: TodoItemFilter) {
this.todoItemFilter = filter;
this.todoItems = [...this.todoItems];
}
This will cause the change detection to detect a 'new' value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.