From 1681da3cdccddff2eaef02e856765543c14f9db0 Mon Sep 17 00:00:00 2001 From: Constantin Simonis Date: Tue, 4 Mar 2025 08:19:29 +0100 Subject: [PATCH] idk --- src/app/app.component.spec.ts | 31 --------------------- src/app/hotel/component/hotels.component.ts | 19 ++++++++++++- src/app/test2/test2.component.ts | 15 ++++++++++ 3 files changed, 33 insertions(+), 32 deletions(-) delete mode 100644 src/app/app.component.spec.ts create mode 100644 src/app/test2/test2.component.ts diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts deleted file mode 100644 index b18bdaf..0000000 --- a/src/app/app.component.spec.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { AppComponent } from './app.component'; - -describe('AppComponent', () => { - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [AppComponent], - }).compileComponents(); - }); - - it('should create the app', () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app).toBeTruthy(); - }); - - it(`should have the 'hotel-manager' title`, () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('hotel-manager'); - }); - - it('should render title', () => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain( - 'Hello, hotel-manager', - ); - }); -}); diff --git a/src/app/hotel/component/hotels.component.ts b/src/app/hotel/component/hotels.component.ts index 46160e9..1f604ac 100644 --- a/src/app/hotel/component/hotels.component.ts +++ b/src/app/hotel/component/hotels.component.ts @@ -1,4 +1,4 @@ -import {ChangeDetectionStrategy, Component, inject} from '@angular/core'; +import {ChangeDetectionStrategy, Component, inject, ViewChild, ViewContainerRef} from '@angular/core'; import {HotelComponent} from './hotel.component'; import {Hotel} from '../model/hotel'; import {FormsModule} from '@angular/forms'; @@ -38,6 +38,12 @@ import {StarComponent} from './star.component'; } @empty {

no matching results for {{ search }}

} +
+
+
+ +
+ `, imports: [ FormsModule, @@ -61,7 +67,18 @@ export class HotelsComponent { public matchingHotels: Observable = this.hotelService.getHotels(); + @ViewChild('example', { read: ViewContainerRef }) + private viewRef!: ViewContainerRef; + public searchEvent(input: string) { this.search = input.toLowerCase(); } + + public async show() { + if (this.viewRef.length === 0) { + const {Test2Component} = await import('../../test2/test2.component'); + + this.viewRef.createComponent(Test2Component); + } + } } diff --git a/src/app/test2/test2.component.ts b/src/app/test2/test2.component.ts new file mode 100644 index 0000000..1bdce8a --- /dev/null +++ b/src/app/test2/test2.component.ts @@ -0,0 +1,15 @@ +import { Component } from '@angular/core'; +import {range} from "rxjs"; + +@Component({ + selector: 'app-test2', + standalone: true, + imports: [], + template: ` + cool website + + + ` +}) +export class Test2Component { +}