Typescript 基于背景颜色在角度图像中添加图像

Typescript 基于背景颜色在角度图像中添加图像,typescript,angular6,Typescript,Angular6,我想添加基于角度背景色的图像。例如,类似这样的内容-> <span *ngIf = "style :'background-color: #somecolor'"> <img></img></span> 如果背景色是从样式表规则应用的,则可以通过读取元素来获取其值 如果元素背景颜色为红色,则在项目值后添加字符串“(此项目为红色)。 通过用图像替换字符串,可以将此逻辑应用于案例 成分 模板 export class AppComponent {

我想添加基于角度背景色的图像。例如,类似这样的内容->

<span *ngIf = "style :'background-color: #somecolor'"> <img></img></span>

如果背景色是从样式表规则应用的,则可以通过读取元素来获取其值

如果元素背景颜色为红色,则在项目值后添加字符串“(此项目为红色)。
通过用图像替换字符串,可以将此逻辑应用于案例

成分 模板
export class AppComponent  {
  items = [
    'item 1',
    'item 2',
    'item 3'
  ];

  isRed(element)
  {
    var color = window.getComputedStyle(element).getPropertyValue("background-color");
    return color === 'rgb(255, 0, 0)';
  }
}
<ul>
  <li *ngFor="let item of items" #itemRef>
    {{item}}
    <span *ngIf="isRed(itemRef)">(This item is red)</span>
  </li>
</ul>
li:nth-child(1) {
  background-color: red;
}

li:nth-child(2) {
  background-color: green;
}

li:nth-child(3) {
  background-color: blue;
}