从管道将图像插入“背景图像”中

时间:2018-10-20 06:26:57

标签: javascript angular

我的html文档中包含以下代码:

<div *ngFor="let search of this.mySearches; let i = index" class="col-sm-6 col-xs-12">
                  <div class="box">
                    <div class="image img-search-rounded">
                      <img [src]="search.postPath | imagenpost: search.generic_category: search.postImg[0]" alt="image" title="image" id="img-rounded" class="img-responsive img-rounded">
                    </div>
                    <div class="pull-left">
                      <h4>{{search.generic_category}}<i class="la la-angle-double-right"></i>{{search.generic_type}}</h4>
                      <p><i class="la la-map-marker"></i>{{search.generic_city}}</p>
                      <p><i class="la la-clock-o"></i> {{search.date | date:'medium'}}</p>
                      <p><i class="la la-circle"></i> Get email notifications</p>
                    </div>
                    <div class="pull-right">
                      <button type="button" [routerLink]="search.url">View</button>
                      <button type="button" (click)="removeMySearch(search._id)">Delete</button>
                    </div>
                  </div>
                </div>

但是我得到了这个,而不是图像:

error image

如何渲染图像?

1 个答案:

答案 0 :(得分:0)

目前尚不清楚您要做什么。似乎您正在尝试使用三元运算符进行“或”运算,但是您缺少了else部分。

条件应该类似于

<div [ngStyle]="{'background-color':person.country === 'UK' ? 'green'
> : 'red' }"></<div>

详细了解示例here