Angular 来自子输入元素的角度4求和值

Angular 来自子输入元素的角度4求和值,angular,ngfor,Angular,Ngfor,我有一个问题我无法解决。 我正在尝试创建一个表,该表将根据每行和每列的输入计算数字 我的申请结构是: TableComponentProjectComponentLineComponentinputComponent Table component.html: <div *ngFor="let project of tableData | projectsPipe"> <div class="row "> <table class="col-sm-8 ta

我有一个问题我无法解决。 我正在尝试创建一个表,该表将根据每行和每列的输入计算数字

我的申请结构是:

TableComponent
ProjectComponent
LineComponent
inputComponent

Table component.html:

<div *ngFor="let project of tableData | projectsPipe">
<div class="row ">
    <table class="col-sm-8 table-dates">
        <tr>
            <td *ngFor="let day of dates;">
                <div><sum></sum></div>
            </td>
            <td>
                <div class="sum">0</div>
            </td>
        </tr>
    </table>
</div>
<div *ngFor="let item of Items">
    <div *ngIf="workitem.teamProject == project.teamProject">
        <div class="item">
            <task-line ></task-line>
        </div>
    </div>
</div>
<div class="row task-line">
<div class="col-sm-4">
    <div class="title">{{title.title}}</div>
</div>
<table class="col-sm-8 table-dates">
    <tr>
        <td *ngFor="let day of dates">
            <table-cell></table-cell>
        </td>
        <td>
            <div class="task-sum-column">{{sum}}</div>
        </td>
    </tr>
</table>

0

和lineComponent.html:

<div *ngFor="let project of tableData | projectsPipe">
<div class="row ">
    <table class="col-sm-8 table-dates">
        <tr>
            <td *ngFor="let day of dates;">
                <div><sum></sum></div>
            </td>
            <td>
                <div class="sum">0</div>
            </td>
        </tr>
    </table>
</div>
<div *ngFor="let item of Items">
    <div *ngIf="workitem.teamProject == project.teamProject">
        <div class="item">
            <task-line ></task-line>
        </div>
    </div>
</div>
<div class="row task-line">
<div class="col-sm-4">
    <div class="title">{{title.title}}</div>
</div>
<table class="col-sm-8 table-dates">
    <tr>
        <td *ngFor="let day of dates">
            <table-cell></table-cell>
        </td>
        <td>
            <div class="task-sum-column">{{sum}}</div>
        </td>
    </tr>
</table>

{{title.title}
{{sum}}

如果我改变例如2,我就无法实现这一点。第3列中的行 金额将重新计算

如何实现这一目标有什么建议吗

编辑: 假设我有这个代码:

    <div *ngFor="let prvky of pole">
    <app-riadok></app-riadok>
</div>
<div>sum : {{sum}}</div>

总和:{{sum}
应用程序riadok是一个具有简单输入的组件,当我更改输入中的值时
我需要再次启动ngFor循环所有组件并求和它们的值,然后在sum div中显示,您应该通过@Input传递引用,请参见

使用ngOnChanges跟踪更改


只要小心,只有当输入不是对象时,才会触发对输入的模型更改。也就是说,它应该是一个

我可以在一行中使用Emmiter从cellComponent值发送到行组件,然后更改总和。但我不知道如何为动态生成的列制作。我可能需要像计算行中的所有值和计算列中的所有值这样的东西,但我不知道如何启动ngFor并从cycleThats中的子元素中获取值。这就是我想说的。您不需要传递任何参数或考虑其更改。发射器仅在子级->父级工作。不是父->子。因此,如果你不使用相同的模型,你将无法跟踪其他孩子的变化。