正在根据 angular 待办事项应用程序中的对象 属性 更新数组的计数

Updating counts of array based on its objects property in angular todo app

我正在 angular 制作一个带有 crud 功能的 todos 应用来学习 angular6 下面的页脚 link 有待完成的待办事项计数器 目前,每次添加和删除待办事项时都会进行计数器更新,但在检查和完成待办事项时,我不想计算剩余的待办事项。 我试图找到一种方法,但我不能。 任何帮助将不胜感激 谢谢 以下是 stackblitz 中项目的 link: stackblitz.com/edit/angular-kxjnyh

您的实现非常接近您的目标。你有方法

public getLength(){
    this.todoService.lengthTodos();
 }

正在从服务读取待办事项长度。您只需要 return 来自服务 class 的值。进行以下更改并在 html.

中使用此函数
  public getLength(){
    return this.allTodos.filter(todo => !todo.completed).length;
  }

更改页脚组件的 html

<span class="todo-count"><strong>{{getLength()}}</strong> item left</span>

这是工作副本 - https://stackblitz.com/edit/angular-zqvxxb