角度2中的条件图像Src绑定 [英] Conditional Image Src Binding in angular 2

查看:74
本文介绍了角度2中的条件图像Src绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Angular 2中编写<img> src的三重条件.

How to write the ternany condition for <img> src in Angular 2.

下面是我尝试过的代码,但这不起作用

Below is the code I tried but this is not working

<img class="lib-img" [src]="item.pictureUrl!= null ? item.pictureUrl : ~/images/logo.png" height="500" width="500" alt="default image">

推荐答案

[src]="item.pictureUrl!= null ? item.pictureUrl : myImgUrl"

然后在您的 .ts

export class App{
   myImgUrl:string='~/images/logo.png';
}

这篇关于角度2中的条件图像Src绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆