This is a good use case for a directive. Something like this is surprisingly useful.
@Directive({
selector: '[removeAfter]'
})
export class RemoveAfter {
constructor(readonly element: ElementRef<HTMLElement>) { }
/**
* Removes the attributed element after the specified number of milliseconds.
* @default `1000`
*/
@Input() removeAfter = 1000;
ngOnInit() {
setTimeout(() => {
this.element.nativeElement.remove();
}, this.removeAfter);
}
}