【发布时间】:2019-04-16 10:44:21
【问题描述】:
在我的 component.ts 文件中,我有一个用户列表。我想在我的 html 中显示它们。
component.html
<ul>
<li *ngFor="let user of users" class="contact-details">
<img [src]="'https://app.compnay.com/{{user.profileImage}}' === ''? '../../../../../../../assets/images/empty-user-profile.png': 'https://app.company.com/{{user.profileImage}}'">
</li>
</ul>
我收到了这个错误
未捕获的错误:模板解析错误:解析器错误:得到插值 ({{}}) 其中表达式应位于第 29 列 ['https://app.company.com.sa/{{user.profileImage}}' === ''? '../../../../../../../assets/images/empty-user-profile.png': 'https://app.company.com.sa/{{user.profileImage}}'] 在 ng:///ChatModule/ContactSearchResultListComponent.html@6:19 ("ass="contact-image">
【问题讨论】:
-
仅供参考,
'https://app.compnay.com/{{user.profileImage}}'永远不能是''。也许您只想检查user.profileImage === '' -
如果没有 url,else 条件将如何呈现?
-
查看 Vitalii 的回答,但条件一开始是错误的,与
else部分无关。 -
是的,正如@FedericoklezCulloca 所说,条件是错误的。它与 Angular 模板引擎有关,而不是您的代码本身。您不能在 1 个语句中同时使用模板绑定和插值。