⚒️ Converting To Standalone Components
To convert our application to use Standalone components, we will mark our component's metadata to indicate that it is a standalone component, and replace the code in our /src/main.ts
to bootstrap our application with our standalone AppComponent
.
Step-By-Step
Here are the step-by-step instructions. A short video of the process is below.
- Delete the file
src/app.module.ts
.- Note: Your application will not be able to compile temporarily. We will fix this soon.
- On the
app.component.ts
metadata, add the propertystandalone: true
. - In the
src/main.ts
, file, delete the code and use thebootstrapApplication
function to tell Angular to start with ourAppComponent
.
Completed /src/app/app.component.ts
/src/app/app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
standalone: true,
template: `
<h1>Hello from {{title}}</h1>
`,
styles: []
})
export class AppComponent {
title = 'Angular';
}
Completed /src/main.ts
/src/main.ts
import { bootstrapApplication } from "@angular/platform-browser";
import { AppComponent } from "./app/app.component";
bootstrapApplication(AppComponent);