/* eslint-disable @angular-eslint/component-selector */
import { AsyncPipe, NgFor } from '@angular/common';
import { Component, inject, Input } from '@angular/core';
import { BehaviorSubject, take } from 'rxjs';
import { AppService } from './app.service';
import { TopicType } from './localDB.service';
@Component({
standalone: true,
selector: 'button-delete-topic',
imports: [AsyncPipe],
template: `
{{ message$$ | async }}
`,
})
export class ButtonDeleteComponent {
@Input() topic!: TopicType;
message$$ = new BehaviorSubject('');
private service = inject(AppService);
deleteTopic() {
this.service
.deleteOldTopics(this.topic)
.pipe(take(1))
.subscribe((result) =>
this.message$$.next(
result
? `All ${this.topic} have been deleted`
: `Error: deletion of some ${this.topic} failed`
)
);
}
}
@Component({
standalone: true,
imports: [AsyncPipe, NgFor, ButtonDeleteComponent],
selector: 'app-root',
template: `
{{ item.id }} - {{ item.topic }}
Delete Food
Delete Sport
Delete Book
`,
})
export class AppComponent {
private service = inject(AppService);
all$ = this.service.getAll$;
}