Angular 如何得到递增后的数字的总值

Angular 如何得到递增后的数字的总值,angular,angular5,Angular,Angular5,我对角5的学习非常陌生,我只想问一下,在它增加后,如何得到这个数的总值 到目前为止,我正在学习教程,我正在使用*ngFor,但我想要的是 但我得到的是这个 这是我的密码 <div class="card-footer clearfix" *ngFor="let item of items"> <div class="float-left p-2"> <i class="fa fa-circle green-text" aria-hidde

我对角5的学习非常陌生,我只想问一下,在它增加后,如何得到这个数的总值

到目前为止,我正在学习教程,我正在使用
*ngFor
,但我想要的是

但我得到的是这个

这是我的密码

<div class="card-footer clearfix" *ngFor="let item of items">
    <div class="float-left p-2">
        <i class="fa fa-circle green-text" aria-hidden="true" mdbTooltip="Active Item" placement="bottom"></i><small class="text-muted"> 0</small>
        <i class="fa fa-circle-o grey-text ml-3" aria-hidden="true" mdbTooltip="Inactive Item" placement="bottom"></i><small class="text-muted"> 0</small>
    </div>
    <div class="float-right">
        <a class="btn btn-link btn-sm waves-light" mdbWavesEffect>View Details</a>
    </div>
</div>

0
0
查看详细信息
我有一个字段为
item.status
的数据,其值为零,只有一个。如果
item.status
的值为零,则灰色圆圈旁边的数字将增加,而如果
item.status
的值为一,则绿色圆圈旁边的数字将增加

此外,我还不清楚
*ngFor
是否正确使用了我的问题


感谢您的帮助。

ngFor
不是您想要做的正确选择<当您想要呈现多个UI元素时,使用code>ngFor。在代码示例中,此行的意思是“为数组
中的每个元素呈现一个div”


在TypeScript代码中编写一个循环,根据您描述的应用程序逻辑计算两个数字。在组件模板中,将这些数字绑定到相应的圆圈旁边。

ngFor
不是正确的选择<当您想要呈现多个UI元素时,使用code>ngFor
。在代码示例中,此行的意思是“为数组
中的每个元素呈现一个div”


在TypeScript代码中编写一个循环,根据您描述的应用程序逻辑计算两个数字。在组件模板中,将这些数字绑定到相应的圆圈旁边。

您应该在键入脚本的旁边循环,并将总计数值绑定到html


ts

让totalOneCount=0;
设totalZeroCount=0;

对于(i=0;i您应该在typescript中循环,并将总计数值绑定到html


ts

让totalOneCount=0;
设totalZeroCount=0;

对于(i=0;i
*ngFor
用于重复模板中的项目。我认为对于您的用例,您更应该在组件代码中进行处理。感谢您的评论,我认为
ngFor
就像一个for循环,如果您想迭代任何内容,可以使用它。您可以循环内容,但它的目的只是为了构建更新HTML,为集合中的每个元素重复一个模板。
*ngFor
用于重复模板中的项目。我认为对于您的用例,您应该在组件代码内部进行处理。感谢您的评论,我认为
ngFor
就像一个for循环,如果您想迭代任何内容,可以使用它。您可以循环使用东西,但它的目的严格来说是为集合中的每个元素建立HTML重复模板。谢谢你的评论,我认为
ngFor
就像一个for循环,如果你想迭代任何东西,你可以使用它。老实说,我对angular非常陌生,所以angular中的所有
ng
基本上都是用于rend的一个UI元素。如果我想在我的应用程序中加入一些逻辑,我需要更改的是ts文件,而不是搜索angular,我需要搜索的是typescript?你需要学习如何在typescript中编写循环:谢谢你的评论,我想,
ngFor
就像一个for循环,如果你想迭代,你可以使用它任何东西。老实说,我对angular非常陌生,所以angular中的所有
ng
基本上都是用来呈现UI元素的。如果我想在我的应用程序中加入一些逻辑,我需要更改的是ts文件,而不是搜索angular,我需要搜索的是关于typescript的内容。你需要学习如何在typescript中编写循环:
let totalOneCount = 0;
let totalZeroCount = 0;

for(i=0;i<item.length;i++){
        if(item[i].status == 1) {
             totalOneCount++;
             continue;
         }
        totalZeroCount++;
    }
<div class="card-footer clearfix">
<div class="float-left p-2">
    <i class="fa fa-circle green-text" aria-hidden="true" mdbTooltip="Active Item" placement="bottom"></i><small class="text-muted"> {{totalOneCount}}</small>
    <i class="fa fa-circle-o grey-text ml-3" aria-hidden="true" mdbTooltip="Inactive Item" placement="bottom"></i><small class="text-muted"> {{totalZeroCount}}</small>
</div>
<div class="float-right">
    <a class="btn btn-link btn-sm waves-light" mdbWavesEffect>View Details</a>
</div>
</div>