Reputation: 2133
How do you display image in div? In my case, it is from the database.
<div *ngFor="let result of results" class="search-res" (click)="showEmployee(result._id)">
<div><img class=""/> {{ result.name }} </div>
</div>
The image's name is result.profile_picture
. How do you add it in the html?
Upvotes: 1
Views: 4240
Reputation: 597
To display your image directly into a div you can add a CSS property with NgStyle:
<div *ngFor="let result of results" class="search-res" (click)="showEmployee(result._id)">
<div [ngStyle]="{ 'background-image': 'url(' + result.image_path+ ')'}">> {{ result.name }} </div>
</div>
Upvotes: 3
Reputation: 7242
you can display image like this. does this help.
<div *ngFor="let result of results" class="search-res" (click)="showEmployee(result._id)">
<div><img src="{{result.profile_picture}}"> {{ result.name }} </div>
</div>
Upvotes: 1