FrontendDeveloper.in

Angular question detail

How to create a standalone component using CLI command?

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

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.

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 {}
Back to all Angular questions
Get LinkedIn Premium at Rs 399