Html 更改另一个div';单击带有角度2的div时的s背景色
我在页面上有一个组件,它有以下divHtml 更改另一个div';单击带有角度2的div时的s背景色,html,angular,typescript,Html,Angular,Typescript,我在页面上有一个组件,它有以下div <div style=" width:400; height:400; float:left"> <div style="background-color:red; width:50%; height:50%; float:left"> </div> <div style="background-color:blue; width:50%; height:50%; float:right"> </
<div style=" width:400; height:400; float:left">
<div style="background-color:red; width:50%; height:50%; float:left">
</div>
<div style="background-color:blue; width:50%; height:50%; float:right">
</div>
<div style="background-color:green; width:50%; height:50%; float:left">
</div>
<div style="background-color:orange; width:50%; height:50%; float:right">
</div>
</div>
我在同一页上有另一个div
<div class="eventBox eventBox__colorBar"></div>
当我点击上面的任何一个div时,我想得到所选的颜色并作为第二个div的背景色应用
如何使用angular2?您可以使用以下代码
<div>
<div style="background-color:red; width:50%; height:50%;" (click)="readColor($event)"> XYZ</div>
<div style="background-color:blue; width:50%; height:50%; float:right" (click)="readColor($event)">blue</div>
<div style="background-color:green; width:50%; height:50%; float:left" (click)="readColor($event)">green</div>
<div style="background-color:orange; width:50%; height:50%; float:right" (click)="readColor($event)">black</div></div></div>
<div [style.background-color]="color">some text here</div>
</div>
@Sajeetharan欢迎您。兄弟。很高兴帮助你,吉上师。:)
readColor(value){
this.color=value.srcElement.style['background-color'];
console.log(value.srcElement.style['background-color']);
}