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
This 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With