This repository has been archived on 2025-04-26. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
angular-hotel-manager/src/app/app.component.ts
Jan Klattenhoff 26ea503cbd
All checks were successful
Build / Build and analyze (push) Successful in 1m41s
feat: update hotel service to use observables
2024-10-22 07:31:24 +02:00

45 lines
1.3 KiB
TypeScript

import { Component, input } from '@angular/core';
import { HotelItem } from './HotelItem/HotelItem.component';
import { SearchComponent } from './Search/search.component';
import { AsyncPipe, 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, range } from 'rxjs';
@Component({
selector: 'app-root',
standalone: true,
imports: [HotelItem, SearchComponent, UpperCasePipe, TextPipe, AsyncPipe],
templateUrl: './app.component.html',
providers: [HotelService],
styleUrl: './app.component.css'
})
export class AppComponent {
public search: string = "";
public hotelService: HotelService = inject(HotelService);
ngOnInit() {
const stream: Observable<number> = range(1, 10);
stream.pipe(
filter((value: number) => value % 2 === 1),
).subscribe((value) => console.log(value));
console.log('---')
stream.pipe(
map((value: number) => value * 2)
).subscribe((value) => console.log(value));
}
public test() {
8
console.log(this.search);
}
public hotels = this.hotelService.getHotels();
public foundHotels = this.hotels.pipe(
filter((hotel) => hotel.hotelName.includes(this.search)),
)
}