File tree Expand file tree Collapse file tree 2 files changed +11
-20
lines changed
apps/rxjs/14-race-condition Expand file tree Collapse file tree 2 files changed +11
-20
lines changed Original file line number Diff line number Diff line change 22 "extends" : " ../tsconfig.json" ,
33 "compilerOptions" : {
44 "outDir" : " ../../../dist/out-tsc" ,
5- "module" : " commonjs " ,
5+ "module" : " es2015 " ,
66 "types" : [" cypress" , " node" ],
77 "sourceMap" : false
88 },
Original file line number Diff line number Diff line change 1- import {
2- ChangeDetectionStrategy ,
3- Component ,
4- inject ,
5- OnInit ,
6- } from '@angular/core' ;
1+ import { AsyncPipe } from '@angular/common' ;
2+ import { ChangeDetectionStrategy , Component , inject } from '@angular/core' ;
73import { MatDialog } from '@angular/material/dialog' ;
8- import { take } from 'rxjs' ;
94import { TopicModalComponent } from './topic-dialog.component' ;
105import { TopicService , TopicType } from './topic.service' ;
116
127@Component ( {
138 selector : 'app-root' ,
149 template : `
15- <button (click)="openTopicModal()">Open Topic</button>
10+ @if (topics$ | async; as topics) {
11+ <button (click)="openTopicModal(topics)">Open Topic</button>
12+ }
1613 ` ,
14+ imports : [ AsyncPipe ] ,
1715 changeDetection : ChangeDetectionStrategy . OnPush ,
1816} )
19- export class AppComponent implements OnInit {
17+ export class AppComponent {
2018 title = 'rxjs-race-condition' ;
2119 dialog = inject ( MatDialog ) ;
2220 topicService = inject ( TopicService ) ;
23- topics : TopicType [ ] = [ ] ;
21+ topics$ = this . topicService . fakeGetHttpTopic ( ) ;
2422
25- ngOnInit ( ) : void {
26- this . topicService
27- . fakeGetHttpTopic ( )
28- . pipe ( take ( 1 ) )
29- . subscribe ( ( topics ) => ( this . topics = topics ) ) ;
30- }
31-
32- openTopicModal ( ) {
23+ openTopicModal ( topics : TopicType [ ] ) {
3324 this . dialog . open ( TopicModalComponent , {
3425 data : {
35- topics : this . topics ,
26+ topics,
3627 } ,
3728 } ) ;
3829 }
You can’t perform that action at this time.
0 commit comments