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

Angular's Future without NgModules: Architectures with Standalone Components

Angular's Future without NgModules: Architectures with Standalone Components

Manfred Steyer

October 26, 2022
Tweet

More Decks by Manfred Steyer

Other Decks in Programming

Transcript

  1. @ManfredSteyer @Component({ standalone: true, selector: 'app-root', imports: [ HomeComponent, AboutComponent,

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

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

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

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

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

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

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

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

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

    'flight-booking', loadChildren: () => import('@nx-example/booking/feature-book') .then(m => m.FLIGHT_BOOKING_ROUTES) }, […] ];
  11. @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) }, ];
  12. @ManfredSteyer export const FLIGHT_BOOKING_ROUTES: Routes = [{ path: '', component:

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

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

    FlightBookingComponent, providers: [ provideState(bookingFeature), provideEffects([BookingEffects]) ], children: [ […] ] }];
  15. @ManfredSteyer + Generates path mappings + Generates initial barrel +

    Prevents bypassing index.ts + Restricting access between libraries
  16. @ManfredSteyer provideRouter & withXYZ Directly point to lazy router configs

    Folders & Barrels Nx, Libs, and Constraints FTW!