October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Generating Code with Angular Schematics: A Practical Guide

Angular schematics generate or modify project files through the CLI. Learn how to run generators, preview changes, configure defaults, and create custom schematics.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Angular schematics are code generators that create or modify project files. Run built-in generators with ng generate, or use a library’s schematics to add setup, generate library-specific code, or apply migrations. To build your own, define rules that transform Angular’s virtual file tree, then preview changes with --dry-run before applying them.

What Angular schematics do

A schematic is a software code generator packaged in a collection, usually distributed as an npm package. It applies instructions to a project by generating or modifying files; it does not create runtime behavior by itself. The resulting files become ordinary project code that you must review, build, and maintain.

As an Amazon Associate I earn from qualifying purchases.

The Angular CLI runs schematics through commands such as ng generate, ng add, and ng update. Its default collection, @schematics/angular, provides generators such as component and service. See Angular’s schematics overview.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run a schematic from the Angular CLI

The general command is ng generate <schematic> [options], also written ng g. For example, ng generate component my-widget invokes the built-in component schematic. A library or custom collection can be named explicitly: ng generate my-schematic-collection:my-schematic-name. The CLI’s generate reference documents the command and its options.

Review the proposed changes before writing them, especially when running an unfamiliar schematic. Use --dry-run (or -d) to report activity without writing files. Use --force only when you intend to allow existing files to be overwritten. The --interactive option controls prompts.

ng generate component my-widget --dry-run
ng generate component my-widget

The first command previews activity; the second runs the generator normally. The CLI’s dry-run output helps you inspect intended file operations, but it does not replace reviewing the generated code.

Set schematic defaults for a workspace

Angular CLI schematic defaults can be configured in angular.json, keyed by collection and schematic name. For example, workspace defaults for the built-in component generator use the key @schematics/angular:component. Consult Angular’s workspace configuration reference for the supported configuration shape and options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How a custom schematic works

A custom schematic transforms Angular’s virtual file tree, called a Tree. Rules read or change that tree and return a transformed version. Operations such as creating, renaming, overwriting, or deleting files are staged as actions; the schematic framework validates the transformations before applying them to the real file system. Authors still need to plan for collisions and merge behavior rather than assuming a staged change will always be safe.

A collection configuration, usually collection.json, maps schematic names to descriptions and factory entry points, and can identify an option schema. The factory entry point creates the rule that performs the transformation. A schema.json describes allowed options, their types, and defaults; schemas can also support prompts for values.

For repeated or structured output, a schematic can include files in a files/ directory and treat them as templates. The rule supplies values used to produce file contents and names. A simple rule that writes a file can suit a small task; templates and workspace-aware rules are more useful when output depends on project structure or user choices. Angular’s authoring guide covers collections, rules, schemas, and templates.

Choose between built-in, custom, and manual changes

  • Use a built-in CLI schematic for standard Angular artifacts such as components or services. It provides a repeatable generator from the default collection.
  • Use a library’s schematic when the library provides setup, artifacts, or migrations tailored to its own conventions.
  • Use manual edits when the change is small and isolated, or when a generator would add unnecessary complexity. For repeated changes, a schematic can make the operation more consistent.
  • Start with a dry run when you want to inspect intended file operations before applying them; omit it when you are ready to make the changes.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How libraries integrate with Angular CLI

Library authors can provide three kinds of CLI behavior:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Add: ng add installs and configures a library. Angular’s documentation uses Angular Material as an example of a library whose add schematic can set up the package and theming.
  • Generate: ng generate can create library-specific artifacts, such as components or services.
  • Update: ng update can update dependencies and run a migration schematic for project edits that would otherwise be manual.

For guidance on registering generation schematics and integrating them into a library, see Angular’s schematics for libraries guide. The broader Angular CLI overview describes the CLI’s role in Angular development.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.