feat: add hotel item component and search functionality

This commit is contained in:
Jan Gleytenhoover 2024-09-10 07:35:29 +02:00
parent f243483688
commit 339dac3999
Signed by: jank
GPG Key ID: B267751B8AE29EFE
13 changed files with 97 additions and 9 deletions

@ -24,7 +24,8 @@
{
"glob": "**/*",
"input": "public"
}
},
"src/assets"
],
"styles": [
"src/styles.css"

@ -0,0 +1,5 @@
<p>Name: {{hotel.hotelName}}</p>
<p>Description: {{hotel.description}}</p>
<p>Price: {{hotel.price}}$</p>
<img src="{{hotel.imageUrl}}" alt="Hotel">
<p class="border-b border-black">{{hotel.rating}}</p>

@ -0,0 +1,14 @@
import { Component } from "@angular/core";
import { ChildComponent } from "../Child/child.component";
import { Input } from "@angular/core";
import { Hotel } from "./hotel";
@Component({
selector: 'app-hotel-item',
standalone: true,
templateUrl: './HotelItem.component.html',
imports: [ChildComponent],
})
export class HotelItem {
@Input() public hotel!: Hotel;
}

@ -0,0 +1,8 @@
export interface Hotel {
hotelId: number;
hotelName: String;
description: String;
price: number;
imageUrl: String;
rating: number;
}

@ -0,0 +1 @@
<input [(ngModel)]="input" (ngModelChange)="update($event)" class="border border-black" type="search">

@ -0,0 +1,20 @@
import { CommonModule } from "@angular/common";
import { Component, NgModule } from "@angular/core";
import { FormsModule, NgForm, NgModel } from "@angular/forms";
import { Input, Output } from "@angular/core";
import { EventEmitter } from "@angular/core";
@Component({
selector: 'app-search',
standalone: true,
templateUrl: './search.component.html',
imports: [FormsModule],
})
export class SearchComponent {
@Input() public input: string = "";
@Output() inputChange = new EventEmitter<string>();
public update(e: string) {
this.inputChange.emit(e);
}
}

@ -1 +1,4 @@
<app-parent></app-parent>
<app-search [(input)]="search"></app-search>
<div *ngFor="let hotel of hotels">
<app-hotel-item *ngIf="hotel.hotelName.includes(search)" [hotel]="hotel"></app-hotel-item>
</div>

@ -1,19 +1,55 @@
import { Component } from '@angular/core';
import { ParentComponent } from './Parent/parent.component';
import { ChildComponent } from './Child/child.component';
import { Component, input } from '@angular/core';
import { HotelItem } from './HotelItem/HotelItem.component';
import { CommonModule } from '@angular/common';
import { SearchComponent } from './Search/search.component';
@Component({
selector: 'app-root',
standalone: true,
imports: [ParentComponent, ChildComponent],
imports: [HotelItem, CommonModule, SearchComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
public test = "Hello";
public search: string = "";
public get age() {
return 17;
public test() {
console.log(this.search);
}
public hotels = [
{
"hotelId": 1,
"hotelName": "Buea süßes Leben",
"description": "Schöne Aussicht am Meer",
"price": 230.5,
"imageUrl": "assets/img/1.jpg",
"rating": 3.5
},
{
"hotelId": 2,
"hotelName": "Marrakesch",
"description": "Genießen Sie den Blick auf die Berge",
"price": 145.5,
"imageUrl": "assets/img/2.jpg",
"rating": 5
},
{
"hotelId": 3,
"hotelName": "Abuja neuer Palast",
"description": "Kompletter Aufenthalt mit Autoservice",
"price": 120.12,
"imageUrl": "assets/img/3.jpg",
"rating": 4
},
{
"hotelId": 4,
"hotelName": "Kapstadt Stadt",
"description": "Wunderschönes Ambiente für Ihren Aufenthalt",
"price": 135.12,
"imageUrl": "assets/img/4.jpg",
"rating": 2.5
}
]
}

BIN
src/assets/img/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 KiB

BIN
src/assets/img/2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

BIN
src/assets/img/3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

BIN
src/assets/img/4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
src/assets/img/5.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB