Skip to content

Commit

Permalink
feat(clientApp): change structure to use standalone components
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelNinyo committed Jul 1, 2024
1 parent bf2c192 commit f5936ec
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 64 deletions.
8 changes: 6 additions & 2 deletions src/Web/ClientApp/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { NavMenuComponent } from './nav-menu/nav-menu.component';

@Component({
selector: 'app-root',
templateUrl: './app.component.html'
selector: 'app-root',
templateUrl: './app.component.html',
standalone: true,
imports: [NavMenuComponent, RouterOutlet]
})
export class AppComponent {
title = 'app';
Expand Down
45 changes: 0 additions & 45 deletions src/Web/ClientApp/src/app/app.module.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/Web/ClientApp/src/app/counter/counter.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe('CounterComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CounterComponent ]
})
imports: [CounterComponent]
})
.compileComponents();
}));

Expand Down
5 changes: 3 additions & 2 deletions src/Web/ClientApp/src/app/counter/counter.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-counter-component',
templateUrl: './counter.component.html'
selector: 'app-counter-component',
templateUrl: './counter.component.html',
standalone: true
})
export class CounterComponent {
public currentCount = 0;
Expand Down
7 changes: 5 additions & 2 deletions src/Web/ClientApp/src/app/fetch-data/fetch-data.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Component } from '@angular/core';
import { WeatherForecastsClient, WeatherForecast } from '../web-api-client';
import { NgIf, NgFor, DatePipe } from '@angular/common';

@Component({
selector: 'app-fetch-data',
templateUrl: './fetch-data.component.html'
selector: 'app-fetch-data',
templateUrl: './fetch-data.component.html',
standalone: true,
imports: [NgIf, NgFor, DatePipe]
})
export class FetchDataComponent {
public forecasts: WeatherForecast[] = [];
Expand Down
5 changes: 3 additions & 2 deletions src/Web/ClientApp/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
selector: 'app-home',
templateUrl: './home.component.html',
standalone: true,
})
export class HomeComponent {
}
10 changes: 7 additions & 3 deletions src/Web/ClientApp/src/app/nav-menu/nav-menu.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Component } from '@angular/core';
import { NgClass } from '@angular/common';
import { RouterLink, RouterLinkActive } from '@angular/router';

@Component({
selector: 'app-nav-menu',
templateUrl: './nav-menu.component.html',
styleUrls: ['./nav-menu.component.scss']
selector: 'app-nav-menu',
templateUrl: './nav-menu.component.html',
styleUrls: ['./nav-menu.component.scss'],
standalone: true,
imports: [RouterLink, NgClass, RouterLinkActive]
})
export class NavMenuComponent {
isExpanded = false;
Expand Down
10 changes: 7 additions & 3 deletions src/Web/ClientApp/src/app/todo/todo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { TodoListsClient, TodoItemsClient,
CreateTodoListCommand, UpdateTodoListCommand,
CreateTodoItemCommand, UpdateTodoItemCommand, UpdateTodoItemDetailCommand
} from '../web-api-client';
import { FormsModule } from '@angular/forms';
import { NgIf, NgFor, NgClass, JsonPipe } from '@angular/common';

@Component({
selector: 'app-todo-component',
templateUrl: './todo.component.html',
styleUrls: ['./todo.component.scss']
selector: 'app-todo-component',
templateUrl: './todo.component.html',
styleUrls: ['./todo.component.scss'],
standalone: true,
imports: [NgIf, NgFor, NgClass, FormsModule, JsonPipe]
})
export class TodoComponent implements OnInit {
debug = false;
Expand Down
31 changes: 28 additions & 3 deletions src/Web/ClientApp/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { enableProdMode } from '@angular/core';
import { enableProdMode, importProvidersFrom } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';

import { environment } from './environments/environment';
import { AppComponent } from './app/app.component';
import { ModalModule } from 'ngx-bootstrap/modal';
import { provideAnimations } from '@angular/platform-browser/animations';
import { TodoComponent } from './app/todo/todo.component';
import { FetchDataComponent } from './app/fetch-data/fetch-data.component';
import { CounterComponent } from './app/counter/counter.component';
import { HomeComponent } from './app/home/home.component';
import { provideRouter } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { BrowserModule, bootstrapApplication } from '@angular/platform-browser';
import { AuthorizeInterceptor } from 'src/api-authorization/authorize.interceptor';
import { HTTP_INTERCEPTORS, withInterceptorsFromDi, provideHttpClient } from '@angular/common/http';

export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
Expand All @@ -16,5 +28,18 @@ if (environment.production) {
enableProdMode();
}

platformBrowserDynamic(providers).bootstrapModule(AppModule)
bootstrapApplication(AppComponent, {
providers: [
importProvidersFrom(BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }), FormsModule, ModalModule.forRoot()),
{ provide: HTTP_INTERCEPTORS, useClass: AuthorizeInterceptor, multi: true },
provideHttpClient(withInterceptorsFromDi()),
provideRouter([
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },
{ path: 'todo', component: TodoComponent }
]),
provideAnimations()
]
})
.catch(err => console.log(err));

0 comments on commit f5936ec

Please sign in to comment.