0
0
Angularframework~10 mins

Creating components with CLI in Angular - Visual Walkthrough

Choose your learning style9 modes available
Concept Flow - Creating components with CLI
Open Terminal
Run CLI Command
Angular CLI Generates Files
Component Files Created
Component Registered Automatically
Use Component in App
This flow shows how running the Angular CLI command creates component files and registers them automatically for use.
Execution Sample
Angular
ng generate component my-new-component

// or shorthand
ng g c my-new-component
This command creates a new Angular component named 'my-new-component' with all necessary files.
Execution Table
StepActionCLI OutputFiles CreatedComponent Registered
1Run command 'ng generate component my-new-component'Starting component generation...None yetNo
2CLI creates folder 'my-new-component'Created folder src/app/my-new-componentFolder createdNo
3CLI creates component filesCreated my-new-component.component.ts, .html, .css, .spec.ts4 files createdNo
4CLI updates app moduleUpdated app.module.ts to declare MyNewComponentFiles unchangedYes
5Component ready to useGeneration completeFiles existYes
💡 Component files created and registered in app module, ready for use.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Files in src/app/my-new-componentNoneFolder created4 files created4 files exist4 files exist
app.module.ts declarationsNo MyNewComponentNoNoMyNewComponent addedMyNewComponent declared
Key Moments - 3 Insights
Why do we see new files created after running the CLI command?
The CLI generates all necessary files for the component (TypeScript, HTML, CSS, test) as shown in execution_table step 3.
How does the component become usable in the app automatically?
The CLI updates app.module.ts to declare the new component, making it usable without manual registration (see step 4).
Can we use a shorthand for the generate component command?
Yes, 'ng g c my-new-component' is a shorthand for 'ng generate component my-new-component' as shown in execution_sample.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step are the component files created?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Check the 'Files Created' column in the execution_table rows.
According to variable_tracker, when is the component declared in app.module.ts?
AAfter Step 3
BAfter Step 4
CAfter Step 2
DAt Start
💡 Hint
Look at the 'app.module.ts declarations' row in variable_tracker.
If you run 'ng g c new-comp', what will happen according to the concept flow?
ANothing, CLI does not recognize shorthand
BCLI only creates files but does not register component
CCLI creates component files and registers component
DCLI deletes existing components
💡 Hint
Refer to concept_flow and execution_sample showing shorthand usage.
Concept Snapshot
Angular CLI creates components quickly:
- Run 'ng generate component name' or 'ng g c name'
- CLI creates folder and 4 files (.ts, .html, .css, .spec.ts)
- CLI updates app.module.ts to declare component
- Component ready to use without manual setup
- Saves time and avoids errors
Full Transcript
This visual execution shows how to create an Angular component using the CLI. First, you open the terminal and run the command 'ng generate component my-new-component' or its shorthand 'ng g c my-new-component'. The CLI then creates a new folder with four files: the TypeScript file, HTML template, CSS stylesheet, and test file. Next, it automatically updates the app.module.ts file to declare the new component, so you don't have to do it manually. Finally, the component is ready to be used in your Angular app. The execution table tracks each step, showing file creation and registration. The variable tracker shows how files and declarations change over time. Key moments clarify why files appear and how the component becomes usable. The quiz tests understanding of when files are created, when the component is declared, and the effect of shorthand commands. This process saves time and helps beginners avoid mistakes when adding components.