Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Better Angular Architectures: Architectures wit...

Better Angular Architectures: Architectures with Standalone Components @DWX2022

Manfred Steyer

July 05, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer Angular 2 BETA, Feb 2016 @Component({ selector: 'app', directives:

    [ROUTER_DIRECTIVES, MyComponent, NgIf, NgFor], templateUrl: 'app/app.html' }) @RouteConfig([ { path: '/', component: Home, … }, { path: '/voucher', component: Voucher, … }, ]) export class App { […] }
  2. @ManfredSteyer Angular 2 RC.5, August 2016 import { NgModule }

    from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; […] @NgModule({ imports: [BrowserModule, OtherModule], declarations: [AppComponent, OtherComponent, OtherDirective], providers: [], bootstrap: [AppComponent], }) export class AppModule {}
  3. @ManfredSteyer Angular 2 RC.5, August 2016 import { NgModule }

    from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; […] @NgModule({ imports: [BrowserModule, OtherModule], declarations: [AppComponent, OtherComponent, OtherDirective], providers: [], bootstrap: [AppComponent], }) export class AppModule {}
  4. @ManfredSteyer Angular 2 RC.5, August 2016 import { NgModule }

    from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; […] @NgModule({ imports: [BrowserModule, OtherModule], declarations: [AppComponent, OtherComponent, OtherDirective], providers: [], bootstrap: [AppComponent], }) export class AppModule {} TypeScript Modules Angular Modules
  5. @ManfredSteyer @Component({ standalone: true, selector: 'app-root', imports: [ HomeComponent, AboutComponent,

    HttpClientModule, ], templateUrl: '…' }) export class AppComponent { […] }
  6. @ManfredSteyer @Component({ standalone: true, selector: 'app-root', imports: [ RouterModule, HomeComponent,

    AboutComponent, ], templateUrl: '…' }) export class AppComponent { […] } @NgModule({ imports: [ RouterModule, HomeComponentModule, AboutComponentModule, ], declares: [ AppComponent ] }) export class AppModule { … } @Component({ selector: 'app-root', templateUrl: '…' }) export class AppComponent { […] }
  7. @ManfredSteyer @Pipe({ standalone: true, name: 'city', pure: true }) export

    class CityPipe implements PipeTransform { […] }
  8. @ManfredSteyer @Directive({ standalone: true, selector: 'input[appCity]', providers: [ … ]

    }) export class CityValidator implements Validator { […] }
  9. @ManfredSteyer @Component({ standalone: true, imports: [ […], FlightCardComponent, CityPipe, CityValidator,

    ], selector: 'flight-search', templateUrl: '…' }) export class FlightSearchComponent { […] }
  10. @ManfredSteyer It looks like you want to use NgIfDirective and

    MyComponent. Shall I import it for you?
  11. @ManfredSteyer → @Component({ standalone: true, selector: 'app-root', imports: [ […]

    TicketsModule, ], templateUrl: '…' }) export class AppComponent { }
  12. @ManfredSteyer → @Component({ standalone: true, selector: 'app-root', imports: [ […]

    TicketsModule, ], templateUrl: '…' }) export class AppComponent { }
  13. @ManfredSteyer export const APP_ROUTES: Routes = [ […], { path:

    'flight-booking', loadChildren: () => import('@nx-example/booking/feature-book') .then(m => m.FLIGHT_BOOKING_ROUTES) }, { path: 'next-flight', loadComponent: () => import('@nx-example/booking/feature-tickets') .then(m => m.NextFlightComponent) }, ];
  14. @ManfredSteyer export const APP_ROUTES: Routes = [ […], { path:

    'flight-booking', loadChildren: () => import('@nx-example/booking/feature-book') .then(m => m.FLIGHT_BOOKING_ROUTES) }, { path: 'next-flight', loadComponent: () => import('@nx-example/booking/feature-tickets') .then(m => m.NextFlightComponent) }, ];
  15. @ManfredSteyer export const FLIGHT_BOOKING_ROUTES: Routes = [{ path: '', component:

    FlightBookingComponent, providers: [ MyService ], children: [ […] ] }];
  16. @ManfredSteyer export const FLIGHT_BOOKING_ROUTES: Routes = [{ path: '', component:

    FlightBookingComponent, providers: [ MyService ], children: [ […] ] }]; (Lazily) loaded with route config Scope: This route + all child routes
  17. @ManfredSteyer export const FLIGHT_BOOKING_ROUTES: Routes = [{ path: '', component:

    FlightBookingComponent, providers: [ ...configureMyLibrary() ], children: [ […] ] }];
  18. @ManfredSteyer import * as booking from './booking'; […] @Component({ standalone:

    true, imports: [ booking, […] ], […] }) export class MyComponent { […] } Wish List
  19. @ManfredSteyer import * as booking from '@demo/booking'; […] @Component({ standalone:

    true, imports: [ ...Object.values(booking) as any[], […] ], […] }) export class MyComponent { […] }
  20. @ManfredSteyer Booking Boarding Shared Feature Feature Feature Feature Feature UI

    UI UI UI UI UI UI UI UI Domain Domain Domain Domain Domain Domain Util Util Util Util Util Util @ManfredSteyer