0
我有一个父级组件,并且在该组件中包含多次其他组件。在Angular 4中单击相同同级组件时更改属性
结构:
父组件:
<table>
<tr class="">
<td>buttons</td>
</tr>
<tr app-myComp></tr>
<tr app-myComp></tr>
<tr app-myComp></tr>
<tr app-myComp></tr>
</table>
儿童(myComp)成分:
@Component({
selector: 'tr[app-myComp]',
template: `
<td><button [style.color]="myColor" (click)="changeColor()">changeColor</button></td>
`
})
export class MyComponent {
myColor: string = "blue";
changeColor(): void{
this.myColor = "red"
}
}
当我点击按钮,按钮改变文字颜色从蓝色到红色。
但我的问题是如何更改文本颜色只有点击按钮红色和重置所有其他按钮的文本颜色为蓝色?
我知道我可以通过@ViewChildren获取MyComponent的列表,但是如何使用它们将按钮的文本颜色重置为蓝色(除了单击它)。
我使用的角度4.3.4
codepen链接:Angular 4 app
谢谢! ..... – AjinkyaBhagwat