我有我的ng-src <img ng-src="{{incident._links.thumbnail.href}}">
,phat来自JSON对象,如果phat为空,如何从<img ng-src="img/default.jpg">
项目文件夹中显示默认图像
这是我的JSON
"_links": {
"self": {
"href": "http://incidents-core/app_dev.php/incidents/5"
},
"attachments": {
"href": "http://incidents-core/app_dev.php/incidents/5/attachments"
},
"comments": {
"href": "http://incidents-core/app_dev.php/incidents/5/comments"
},
"thumbnail": {
"href": "http://incidents-core/app_dev.php/attachments/49/download"
}
}
这是空的
"_links": {
"self": {
"href": "http://incidents-core/app_dev.php/incidents/5"
},
"attachments": {
"href": "http://incidents-core/app_dev.php/incidents/5/attachments"
},
"comments": {
"href": "http://incidents-core/app_dev.php/incidents/5/comments"
}
}
答案 0 :(得分:2)
<img ng-src="{{incident._links.thumbnail.href || 'img/default.jpg'}}">
答案 1 :(得分:0)
您可以使用ng-if
或ng-show/ng-hide
来完成此操作。
提出这样的条件
<img ng-src="{{incident._links.thumbnail.href}}"
ng-show="incident._links.thumbnail.href !== undifined && incident._links.thumbnail.href !== ''>
<img ng-src="img/default.jpg"
ng-show="incident._links.thumbnail.href === undifined || incident._links.thumbnail.href === ''>