From d1cc5b076d7c6890d85ee7047bd02197ef71f808 Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Tue, 1 Oct 2024 08:27:41 +0200 Subject: [PATCH] feat(app): add observable stream processing in ngOnInit --- src/app/app.component.ts | 22 ++++++++++++++++++++++ src/main.ts | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index bc03eb1..6c1f47b 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -5,6 +5,7 @@ import { UpperCasePipe } from '@angular/common'; import { TextPipe } from '../text.pipe'; import { HotelService } from './Parent/services/hotel.service'; import { inject } from '@angular/core'; +import { filter, map, Observable } from 'rxjs'; @Component({ selector: 'app-root', @@ -18,6 +19,27 @@ export class AppComponent { public search: string = ""; public hotelService: HotelService = inject(HotelService); + ngOnInit() { + const stream: Observable = new Observable((observer) => { + observer.next(1); + observer.next(2); + observer.next(3); + observer.next(4); + observer.next(5); + observer.next(6); + observer.next(7); + observer.next(8); + observer.next(9); + observer.next(10); + observer.complete(); + }); + + stream.pipe( + filter((value:number) => value % 2 === 1), + map((value:number) => value * 2) + ).subscribe((value) => console.log(value)); + } + public test() { console.log(this.search); } diff --git a/src/main.ts b/src/main.ts index 35b00f3..7ff0c7e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,10 @@ import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; +import { Observable } from 'rxjs'; + + + bootstrapApplication(AppComponent, appConfig) .catch((err) => console.error(err));