0Pricing
Angular Academy · Lesson

Generating Code with ng generate

Scaffold components, services, and more.

Generating Code with ng generate is a free Angular Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Generating Code with ng generate

The ng generate command (shortened to ng g) scaffolds Angular building blocks with correct boilerplate and naming conventions.

Generating a Component

Create a standalone component with one command.

ng generate component hello
# short form:
ng g component hello

What Gets Created

It generates hello.component.ts, .html, the stylesheet, and a .spec.ts test, and uses standalone by default.

Generating into a Folder

Provide a path to place the component in a subfolder.

ng g component features/dashboard

Generating a Service

Create an injectable service with the service schematic.

ng g service data
# creates data.service.ts with @Injectable

Generating a Directive

Standalone directives are scaffolded similarly.

ng g directive highlight

Generating a Pipe

Create a custom pipe for template transformations.

ng g pipe truncate

Generating a Guard

Route guards protect navigation. The CLI scaffolds functional guards.

ng g guard auth

Dry Run Preview

Use the dry-run flag to preview what would be created without writing files.

ng g component hello --dry-run

Skipping the Test File

Add a flag to skip generating the .spec.ts test if you do not want one.

ng g component hello --skip-tests

Inline Template and Styles

You can request inline template and styles instead of separate files.

ng g component badge --inline-template --inline-style

Quick Check: ng generate

Scaffolding building blocks.

Recap: Generate

ng generate (ng g) scaffolds components, services, directives, pipes, and guards with correct conventions. Flags like --dry-run, --skip-tests, and --inline-template tailor the output. Next: building and serving.

Frequently asked questions

Is the “Generating Code with ng generate” lesson free?

Yes — the full text of “Generating Code with ng generate” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.

What will I learn in “Generating Code with ng generate”?

Scaffold components, services, and more. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Angular Academy?

No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Generating Code with ng generate” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Angular Academy lesson?

Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Generating a New Project
  2. Project Structure Explained
  3. Generating Code with ng generate
  4. Building and Serving
← Back to Angular Academy