This is my repeater:
<div ng-click="selected(entity)" ng-if="entity.is_organization == true">
<div class="row">
<div class="cell info">
<span class="text" ng-bind-html="entity.label"></span>
</div>
<div class="cell img" ng-show="isImageAvailable">
<img class="image" ng-src="checkImageAvailable(entity.thumbnail[0])">
</div>
</div>
</div>
checkImageAvailable in the controller:
$scope.isImageAvailable = false;
$scope.checkImageAvailable = function(image_url){
var img = new Image();
img.onload = function (){
$scope.isImageAvailable = true;
};
img.onerror = function (){
$scope.isImageAvailable = false;
};
img.src = image_url;
if($scope.isImageAvailable){
return image_url;
}
};
I get the entity.thumbnail[0] from the JSON, but even it has a URL it doesnt exist. So I do check it using checkImageAvailable. If image is not available, set isImageAvailable set to false, so image parent container ng-show is taken care to hide the image placeholder from browser.
Same time on the console log it shows:
http://localhost/checkImageAvailable(entity.thumbnail[0]) is 404
What may be the mistake I'm doing in front of AngularJS.
onloadis asynchronous so your function will never return the url.