mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 21:03:03 -05:00
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import {
|
|
ChangeDetectionStrategy,
|
|
Component,
|
|
inject,
|
|
OnInit,
|
|
} from '@angular/core';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { take } from 'rxjs';
|
|
import { TopicModalComponent } from './topic-dialog.component';
|
|
import { TopicService, TopicType } from './topic.service';
|
|
|
|
@Component({
|
|
standalone: true,
|
|
selector: 'app-root',
|
|
template: ` <button (click)="openTopicModal()">Open Topic</button> `,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
})
|
|
export class AppComponent implements OnInit {
|
|
title = 'rxjs-race-condition';
|
|
dialog = inject(MatDialog);
|
|
topicService = inject(TopicService);
|
|
topics: TopicType[] = [];
|
|
|
|
ngOnInit(): void {
|
|
this.topicService
|
|
.fakeGetHttpTopic()
|
|
.pipe(take(1))
|
|
.subscribe((topics) => (this.topics = topics));
|
|
}
|
|
|
|
openTopicModal() {
|
|
this.dialog.open(TopicModalComponent, {
|
|
data: {
|
|
topics: this.topics,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
// faire une app qui fonctionne mais pas dans les tests e2e à cause du délai de la requete http.
|