From: Kai Moritz Date: Wed, 17 Sep 2025 19:04:37 +0000 (+0200) Subject: refactor: Migrated the project to standalone -- step 3 X-Git-Tag: jest--2025-10-04--09-27~24 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=44e3e02b3807d9c539e0c912113b54c79eb8447b;p=demos%2Fkafka%2Fchat refactor: Migrated the project to standalone -- step 3 prong generate @angular/core:standalone ? Choose the type of migration: Bootstrap the application using standalone APIs ? Which path in your project should be migrated? ./ --- diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 97e5fe9e..de0b395e 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -6,9 +6,7 @@ describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [ - RouterTestingModule - ], - declarations: [ + RouterTestingModule, AppComponent ], }).compileComponents(); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9a05a567..b8ce6018 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,9 +1,12 @@ import { Component } from '@angular/core'; +import { RouterOutlet } from '@angular/router'; @Component({ selector: 'app-root', templateUrl: './app.component.html', - styleUrls: ['./app.component.less'] + styleUrls: ['./app.component.less'], + standalone: true, + imports: [RouterOutlet], }) export class AppComponent { title = 'chatroom-frontend'; diff --git a/src/app/app.module.ts b/src/app/app.module.ts deleted file mode 100644 index 22f37b8f..00000000 --- a/src/app/app.module.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { NgModule } from '@angular/core'; -import { BrowserModule } from '@angular/platform-browser'; -import { ReactiveFormsModule } from "@angular/forms"; -import { HttpClientModule } from '@angular/common/http'; - -import { AppRoutingModule } from './app-routing.module'; -import { AppComponent } from './app.component'; -import { ChatroomsComponent } from './chatrooms/chatrooms.component'; -import { UserComponent } from './user/user.component'; -import { ChatroomComponent } from './chatroom/chatroom.component'; - -@NgModule({ - declarations: [ - AppComponent - ], - imports: [ - BrowserModule, - ReactiveFormsModule, - HttpClientModule, - AppRoutingModule, - ChatroomsComponent, - UserComponent, - ChatroomComponent - ], - providers: [], - bootstrap: [AppComponent], -}) -export class AppModule { } diff --git a/src/main.ts b/src/main.ts index c58dc05c..2ea3c5fa 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,23 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { AppModule } from './app/app.module'; +import { importProvidersFrom } from '@angular/core'; +import { AppComponent } from './app/app.component'; +import { AppRoutingModule } from './app/app-routing.module'; +import { withInterceptorsFromDi, provideHttpClient } from '@angular/common/http'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserModule, bootstrapApplication } from '@angular/platform-browser'; -platformBrowserDynamic().bootstrapModule(AppModule) + +bootstrapApplication(AppComponent, { + providers: [ + importProvidersFrom( + BrowserModule, + ReactiveFormsModule, + AppRoutingModule, + ), + provideHttpClient( + withInterceptorsFromDi(), + ) + ]}) .catch(err => console.error(err));