I am currently working on a project to showcase a list of names along with their corresponding images.
To achieve this, I have set up a service that includes all the names and associated images:
import { Case } from './case';
export const CASES: Case[] = [
{ name: 'Diesel', image: '/assets/images/diesel.png', link: '' },
{ name: 'WeWork Berlin', image: '/assets/images/berlin.png', link: '' },
{ name: 'Fritzhansen', image: '/assets/images/fritzhansen.png', link: '' },
{ name: 'Savum', image: '/assets/images/savum.png', link: '' },
{ name: 'Eskay', image: '/assets/images/eskay.png', link: '' },
{ name: 'Diesel', image: '/assets/images/diesel-snd.png', link: '' },
{ name: 'Mobilia', image: '/assets/images/mobilia.png', link: '' },
{ name: 'Rarekind', image: '/assets/images/rarekind.png', link: '' }
];
The list of cases is retrieved in the case-list component.ts file:
import {Component, OnInit} from '@angular/core';
import { CASES } from '../mock/mock-cases';
@Component({
selector: 'app-case-list',
templateUrl: './case-list.component.html',
styleUrls: ['./case-list.component.scss']
})
export class CaseListComponent implements OnInit {
cases = CASES;
...
}
In the case-list's HTML file, I am using a loop to display the names and their images:
<div *ngFor="let case of cases" class="container-fluid d-flex justify-content-center">
<ul>
<li class="text-center">
{{ case.name }}
</li>
</ul>
<img src="{{ case.image }}" alt="First" class="position-absolute align-self-center d-none">
</div>
However, I want to enhance this functionality. Currently, all images are visible at once.
My goal is to make the image appear only when the corresponding li
item is hovered over. Moreover, I want only the image linked to the hovered li
item to be displayed - for example, if the "Savum" item is hovered over, only its image 'savum.png' should show.
How can I implement this feature in Angular?