Angular 如何通过角度传感器上的组件传递动态参数?

Angular 如何通过角度传感器上的组件传递动态参数?,angular,components,Angular,Components,所以我的问题是,我想让一个参数通过Angular app中的两个组件,当我在第一个组件上更改它的值时,第二个组件上的值也会更改 在这里的示例中,我有一个游戏组件,其中我可以修改两个数字值(行和列),还有一个网格组件(在游戏组件中调用),它将显示一个HTML表,其中包含游戏组件中可以动态更改的行和列的数量 下面是game.component.html <header> <h1> Test App </h1> </header

所以我的问题是,我想让一个参数通过Angular app中的两个组件,当我在第一个组件上更改它的值时,第二个组件上的值也会更改

在这里的示例中,我有一个游戏组件,其中我可以修改两个数字值(行和列),还有一个网格组件(在游戏组件中调用),它将显示一个HTML表,其中包含游戏组件中可以动态更改的行和列的数量

下面是
game.component.html

<header>
    <h1>
        Test App
    </h1>
</header>

<div>
    Number of rows: {{row}}
    <button (click)="addRow()" >+</button>
    <button (click)="removeRow()" >-</button>
</div>

<div>
    Number of columns: {{column}}
    <button (click)="addColumn()" >+</button>
    <button (click)="removeColumn()" >-</button>
</div>

<grid [row]="row" [column]="column" >
</grid>
<table>
    <tr *ngFor="let r of row">
        <td *ngFor="let c of column">
            test
        </td>
    </tr>
</table>
下面是
grid.component.html

<header>
    <h1>
        Test App
    </h1>
</header>

<div>
    Number of rows: {{row}}
    <button (click)="addRow()" >+</button>
    <button (click)="removeRow()" >-</button>
</div>

<div>
    Number of columns: {{column}}
    <button (click)="addColumn()" >+</button>
    <button (click)="removeColumn()" >-</button>
</div>

<grid [row]="row" [column]="column" >
</grid>
<table>
    <tr *ngFor="let r of row">
        <td *ngFor="let c of column">
            test
        </td>
    </tr>
</table>

也许你正在寻找的方式是使用服务。这可能吗?这能回答你的问题吗?