This is a list of items each one contain an image I want to display the placeholder untill the image in that card is loaded what is the condition in the @defer() to make it
@for (item of places; track $index) {
@defer (){
<div [routerLink]="['/place/'+item.id]" class="row item container-fluid py-2" style="cursor: pointer;">
<div class="col-lg-4">
<img style="height: 250px;" src="{{item.image}}" alt="">
</div>
<div class="col-lg-8 pt-4">
<h4>{{item.name}}</h4>
<h5 class="text-secondary">{{item.adress}}</h5>
<h6 class="text-secondary">
{{item.bio| truncate:200 }}
</h6>
<div class="d-flex align-items-center">
<p class="fw-bold m-0 me-2">{{calculateAverageRate(item)| number:'1.1-1'}}/5</p>
<div class="rating">
<input value="5" name="rating" id="star5" type="radio">
<label [style.color]="calculateAverageRate(item)>=5? '#6f00ff' : '#acacac'" for="star5"></label>
<input value="4" name="rating" id="star4" type="radio">
<label [style.color]="calculateAverageRate(item)>=4? '#6f00ff' : '#acacac'" for="star4"></label>
<input value="3" name="rating" id="star3" type="radio">
<label [style.color]="calculateAverageRate(item)>=3? '#6f00ff' : '#acacac'" for="star3"></label>
<input value="2" name="rating" id="star2" type="radio">
<label [style.color]="calculateAverageRate(item)>=2? '#6f00ff' : '#acacac'" for="star2"></label>
<input value="1" name="rating" id="star1" type="radio">
<label [style.color]="calculateAverageRate(item)>=1? '#6f00ff' : '#acacac'" for="star1"></label>
</div>
</div>
</div>
</div>}
@placeholder {
<div>placeholder </div>
}
The defer condition is empty in my code what is the condition to fill it
You can use the angular directive
NgOptimizedImageto make a place holder or use the variety of options to achieve what you need. Please find below working example when I use place holder with a dataURL image which will load before the image loads,Full Docs for NgOptimizedImage
snippet
full code
Stackblitz Demo