0

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 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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
Updated the link and answer - stackblitz.com/edit/angular-zqvxxb
Thanks for the support

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.