InterviewHubPRO
Section Overview
Q277

Question 277 of 283

Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)

98%
Angular & Signals (283 Qs)•Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)

How to create a standalone component using CLI command?

Generate a standalone component using the CLI command as shown below:

bash
ng generate component component-name --standalone

On running the command standalone component is created. Here is the list of file created.

  1. component-name.component.ts
  2. component-name.component.css
  3. component-name.component.spec
  4. component-name.component.html

Next need to update app.module.ts as shown below.

typescript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ComponentNameComponent } from './component-name/component-name.component';

@NgModule({
 imports: [
   BrowserModule,
   ComponentNameComponent
 ],
 declarations: [AppComponent],
 bootstrap: [AppComponent],
})
export class AppModule {}