Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用*ngFor循环计算数组中重复/空项的数量_Javascript_Arrays_Angular_Ngfor - Fatal编程技术网

Javascript 如何使用*ngFor循环计算数组中重复/空项的数量

Javascript 如何使用*ngFor循环计算数组中重复/空项的数量,javascript,arrays,angular,ngfor,Javascript,Arrays,Angular,Ngfor,例如,其中一些没有颜色: items = [ { messageTagId: "1", description: "Test Tag1" }, { messageTagId: "2", description: "Test Tag1", tagColor: "#ff0000" }, { messageTagId: "3",

例如,其中一些没有颜色:

items = [
       {
        messageTagId: "1",
        description: "Test Tag1"

       }, 
       {
        messageTagId: "2",
        description: "Test Tag1",
        tagColor: "#ff0000"
       }, 
       {
        messageTagId: "3",
        description: "Test Tag1"

       }, 
       {
        messageTagId: "4",
        description: "Test Tag1",
        tagColor: "#ff0000"
       }, 
       {
        messageTagId: "5",
        description: "Test Tag1",
        tagColor: "#ff0000"
       }, 
        ]
显示:应计算完全没有颜色且具有颜色特性的

  [2] [3]
其中2个不带颜色,3个带颜色

这是我的*ngFor循环,但它不正确。这应该用[2]创建一个跨距,用[3]创建第二个跨距

  <span *ngFor="let messageTag of items" >{{items.length}}</span>
{{items.length}
我首先需要过滤器

在组件上执行以下操作:

const newItems = items.filter(item => !item.color)
在HTML上执行以下操作:

<span *ngFor="let messageTag of newItems" >{{messageTag.messageTagId}}</span>
{{messageTag.messageTagId}