I am making a todos app with crud functionality in angular to learn angular6 Below in footer link there is counter of todos that are remained to complete currently counter updates everytime with adding and removing todos, but on check and when todo is completed i dont want to count in todos left. I am trying to find a way but i cant. Any help will be appreciated Thanks Below is link of project in stackblitz: stackblitz.com/edit/angular-kxjnyh
1 Answer
Your implementation is pretty close what you are trying to do. You have method
public getLength(){
this.todoService.lengthTodos();
}
Which is reading the todo length from the service. You just need to return the value from service class. Make the following changes and use this function in html.
public getLength(){
return this.allTodos.filter(todo => !todo.completed).length;
}
Change in the html of footer component
<span class="todo-count"><strong>{{getLength()}}</strong> item left</span>
Here is the working copy - https://stackblitz.com/edit/angular-zqvxxb
3 Comments
Darshit
Thanks, It worked just fine as per my question, but it stops clearCompleted to work and throws error. The problem is in isCompleted(todoService) something i am missing
Sunil
Updated the link and answer - stackblitz.com/edit/angular-zqvxxb
Darshit
Thanks for the support