What is a component in Angular?
Why Interviewers Ask This
This is a classic screening question for Angular roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
A component is the basic building block of an Angular application — it controls a patch of the screen (the view). Every component consists of three parts: (1) TypeScript class: contains the component's logic, properties (data), and methods. Decorated with @Component(); (2) HTML template: defines the component's view. Can be inline or external file. Uses Angular template syntax (data binding, directives); (3) CSS styles: optional scoped styles that apply only to this component's view. The @Component decorator provides metadata: @Component({ selector: "app-user-card", templateUrl: "./user-card.component.html", styleUrls: ["./user-card.component.css"] }). selector: CSS selector that identifies this component in parent templates (<app-user-card>). Data flow: @Input() properties receive data from parent; @Output() EventEmitter properties send events to parent. Generating a component via CLI: ng generate component user-card (or ng g c user-card) — creates 4 files: .ts, .html, .css, .spec.ts, and updates the module. Standalone components (Angular 14+): components that don't belong to any NgModule, declared with standalone: true in @Component — can directly import what they need.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Angular project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is the difference between AngularJS and Angular?
Next
What is a module (NgModule) in Angular?