admin管理员组文章数量:1291026
What could be the best possible condition to check and display if the image path is undefined in AngularJS. I have tried like this:
HTML:
<div ng-src="{{imageUrl}}" == "null" || src="img/avatar.png" >
CONTROLLER:
$scope.imageUrl="125.178.1.127/uploads/image" +$scope.imageName;
If $scope.imageName is undefined I have to load/show the default image img/avatar.png
What could be the best possible condition to check and display if the image path is undefined in AngularJS. I have tried like this:
HTML:
<div ng-src="{{imageUrl}}" == "null" || src="img/avatar.png" >
CONTROLLER:
$scope.imageUrl="125.178.1.127/uploads/image" +$scope.imageName;
If $scope.imageName is undefined I have to load/show the default image img/avatar.png
- possible duplicate of if a ngSrc path resolves to a 404, is there a way to fallback to a default? – Josh C. Commented Mar 30, 2015 at 12:53
- But my condition dosen't resolve to a 404.It gets undefined instead – forgottofly Commented Mar 30, 2015 at 12:54
2 Answers
Reset to default 8This should work:
<div ng-src="{{imageName ? imageUrl : 'img/avatar.png'}}">
I use the Angular Image Fallback modul and perfectly works! Just place fallback-src and loading-src to the image tag.
In your modul:
angular.module('starter', ['dcbImgFallback'])
In your HTML:
<img ng-src="your image path" fallback-src="your image default" loading-src="your image loading">
This is also works in ng-repeat. Hope this can helps.
本文标签: javascriptReplace with default image if image not found angularjsStack Overflow
版权声明:本文标题:javascript - Replace with default image if image not found -angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741518020a2383011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论