Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 更改另一个div';单击带有角度2的div时的s背景色_Html_Angular_Typescript - Fatal编程技术网

Html 更改另一个div';单击带有角度2的div时的s背景色

Html 更改另一个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

<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']);
  }