forgottofly forgottofly - 2 years ago 309
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:

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

$scope.imageUrl="" +$scope.imageName;

If $scope.imageName is undefined I have to load/show the default image

Answer Source

This should work:

<div ng-src="{{imageName ? imageUrl : 'img/avatar.png'}}">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download