javascript - 如果找不到图像,则替换为默认图像-angularjs

标签 javascript angularjs image

如果图像路径在 AngularJS 中未定义,检查和显示的最佳条件是什么。 我试过这样:

HTML:
<div ng-src="{{imageUrl}}" == "null" || src="img/avatar.png" >

CONTROLLER:
$scope.imageUrl="125.178.1.127/uploads/image" +$scope.imageName;

如果 $scope.imageName 未定义,我必须加载/显示默认图像 img/avatar.png

最佳答案

这应该有效:

<div ng-src="{{imageName ? imageUrl : 'img/avatar.png'}}">

关于javascript - 如果找不到图像,则替换为默认图像-angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29346670/

相关文章:

javascript - AngularJS + Bootstrap - 将 $compiled HTML 注入(inject) popover

javascript - AngularJS 是否总是知道什么时候发生了变化,是时候更新了?

html - Bootstrap 面板边框显示不正确

c# - 在 WPF 中通过 XAML 代码加载外部图像?

javascript - YouTube 播放器.destroy();抛出 'this.a is null' ,即使在验证玩家时也是如此

javascript - 返回 NAN 的阶乘函数

javascript - 如何为这个原型(prototype)创建一个界面?

javascript - Jasmine ——测试 promise 。如何在回调中测试函数?

Java字节图像操作

python - 使用 image_slicer.py 将切片加入完整图像