If you can explain more about what are you going to do would be helpful, or post the whole code how you did it that makes a click the whole list disappears so that I can get some hint what you might want to do.
To what you've described, there are couple ways you can achieve it. One way to manipulate the array (activities) every time clicks.
see stackblitz
activities = [1, 2, 3, 4];
startActivity(activity: any) {
// Remove the clicked activity from the array.
this.activities = this.activities.filter(value => value !== activity);
}
Another way like what @Roman A. suggested, giving a tag for each activity.
see stackblitz
<div *ngFor="let activity of activities">
<a (click)="startActivity(activity)">
<button *ngIf="activity.show">Icon {{activity.value}}</button>
</a>
</div>
export class AppComponent {
activities: ActivityModel[] = [
{ value: 1, show: true },
{ value: 2, show: true },
{ value: 3, show: true },
{ value: 4, show: true }
];
startActivity(activity: ActivityModel) {
activity.show = false;
}
}
interface ActivityModel {
value: any;
show: boolean;
}
Note:
- using
<a>
tag as a button and binding event on it should be caution, if you are having a href
property on it, it may mess up with the event binding.
- angular *ngFor always recommended to add a trackBy function, see how to use trackBy