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

Angular Without Modules - Google I/O Extended Nairobi

Angular Without Modules - Google I/O Extended Nairobi

In the recently released version Angular, version 14, Angular enables the usage of Angular without the need for NgModules. This talk will look at how Angular Standalone components work, how to use them, and what you need to do to prepare your existing Angular project for Standalone Components.

Maina Wycliffe

June 06, 2022
Tweet

More Decks by Maina Wycliffe

Other Decks in Programming

Transcript

  1. About Me Software Engineer, Typescript aficionado @mwycliffe_dev This is Learning

    @Thisis_Learning Author of the All Things Typescript Newsletter - allthingstypescript.dev Maina Wycliffe
  2. - Basic Building Blocks of Angular - Containers for components,

    directives, pipes, etc. - Providing Dependency Injection - Imports and Export - Bootstrapping root component Why?
  3. - Affects Components, Pipes, Directives - Components that can be

    used without NgModules - In developer preview - Standalone property for standalone components - Angular 14 Feature What’s changing
  4. app.component.ts @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'],

    imports: [RouterModule, CommonModule], }) export class AppComponent {} Indicates a component is a Standalone component
  5. date-time.pipe.ts @Pipe({ name: 'dateTime', standalone: true, }) export class DateTimePipe

    implements PipeTransform { transform(value: unknown, ...args: unknown[]): string | null { // ... } } Indicates a pipe is a Standalone pipe
  6. - Delete the root module - app.module.ts - Modify main.ts

    and replace bootstrapModule() with bootstrapApplication() Migrating to Standalone Components
  7. importProvidersFrom - Extracts providers from the provided module - The

    providers are made available to the root component and it’s children
  8. New Components Using the ng generate with --standalone flag to

    generate standalone components i.e. ng g component component-name --standalone ng g directive directive-name --standalone ng g pipe pipe-name --standalone
  9. Using Standalone Components - Import standalone component, directive, pipe -

    Imports – property can also import other modules - providers - property for Dependency Injection