forgottofly forgottofly - 7 months ago 207
Javascript Question

Replace with default image if image not found -angularjs

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

Answer

This should work:

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