The task is to show image in template, but only if image dimensions ratio > 2
<img class="main-img" ng-if="showImage($index)" ng-src="{{item.img}}">
Function:
$scope.showImage = function(index) {
var img = new Image();
img.src = $scope.items[index].img;
img.addEventListener("load", function() {
var ratio = this.naturalWidth / this.naturalHeight;
if (ratio > 2) {
return true;
} else {
return false;
}
})
}
ng-if doesn't wait for image loading. How to fix? Thanks.