Question presented to candidate: "Walk me through what a component is in Angular, what an NgModule is, and whether a new Angular app still needs modules."
What a strong answer should cover:
- A component is a TypeScript class with
@Componentmetadata: a selector, a template, optional styles, and the dependencies its template uses. - An app is a tree of components; the root one is bootstrapped and the rest appear through their selectors.
- An NgModule (
@NgModule) groups declarations and defines a compilation context:declarations,imports,exports,providers,bootstrap. - Since v19, components, directives and pipes are standalone by default and list their own
imports; NgModules are optional, not deprecated. - Standalone and NgModule code interoperate: a standalone component can import an NgModule, and a module can import standalone components.
- Typical mistakes: declaring a standalone component, declaring a component in two modules, forgetting
exports.
Clarifying questions expected:
- "Is this a new app, or an existing one built on NgModules?"
- "Do you want the template-compilation view, or how modules affect providers and lazy loading?"
Code / implementation expected: Yes β a standalone component tree, plus one NgModule-based component used from it.