Last active
May 13, 2022 17:28
-
-
Save twerske/6fa8f71a37cf28a24c439e01325784a4 to your computer and use it in GitHub Desktop.
Simplifying Angular with Standalone Components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; // includes NgIf and TitleCasePipe | |
import { bootstrapApplication } from '@angular/platform-browser'; | |
import { MatCardModule } from '@angular/material/card'; | |
import { ImageComponent } from './app/image.component'; | |
import { HighlightDirective } from './app/highlight.directive'; | |
@Component({ | |
selector: 'app-root', | |
standalone: true, | |
imports: [ | |
ImageComponent, HighlightDirective, // import standalone Components, Directives and Pipes | |
CommonModule, MatCardModule // and NgModules | |
], | |
template: ` | |
<mat-card *ngIf="url"> | |
<app-image-component [url]="url"></app-image-component> | |
<h2 app-highlight>{{name | titlecase}}</h2> | |
</mat-card> | |
` | |
}) | |
export class ExampleStandaloneComponent { | |
name = "emma"; | |
url = "www.emma.org/image"; | |
} | |
// Bootstrap a new Angular application using our `ExampleStandaloneComponent` as a root component. | |
bootstrapApplication(ExampleStandaloneComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment