Generating Code with ng generate
Scaffold components, services, and more.
Generating Code with ng generate is a free Angular Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.
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 helloWhat 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/dashboardGenerating a Service
Create an injectable service with the service schematic.
ng g service data
# creates data.service.ts with @InjectableGenerating a Directive
Standalone directives are scaffolded similarly.
ng g directive highlightGenerating a Pipe
Create a custom pipe for template transformations.
ng g pipe truncateGenerating a Guard
Route guards protect navigation. The CLI scaffolds functional guards.
ng g guard authDry Run Preview
Use the dry-run flag to preview what would be created without writing files.
ng g component hello --dry-runSkipping the Test File
Add a flag to skip generating the .spec.ts test if you do not want one.
ng g component hello --skip-testsInline Template and Styles
You can request inline template and styles instead of separate files.
ng g component badge --inline-template --inline-styleQuick 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.
Learn HTML with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 38
- Lessons
- 144
Frequently Asked Questions
Is the “Generating Code with ng generate” lesson free?
Yes — any 3 lessons of the Angular Academy learning path, including “Generating Code with ng generate”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.
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
- Generating a New Project
- Project Structure Explained
- Generating Code with ng generate
- Building and Serving