Which scenario best justifies using standalone components instead of module-based components in Angular?
Think about simplicity and avoiding extra setup for small, isolated components.
Standalone components are ideal for small, self-contained features that don't require the overhead of modules. They simplify the code and reduce boilerplate.
Given two Angular components, one standalone and one module-based, how does the standalone: true flag affect importing other components or directives?
Consider where dependencies are declared for standalone components versus module-based components.
Standalone components declare their dependencies directly in their imports array, removing the need for NgModules to manage dependencies.
Which of the following Angular component declarations correctly defines a standalone component?
Check the type and presence of the standalone property.
The standalone property must be a boolean true (not string) to declare a standalone component.
Which statement about Angular component lifecycle hooks is true when comparing standalone and module-based components?
Think about whether Angular changes lifecycle behavior based on component type.
Standalone components behave the same as module-based components regarding lifecycle hooks; Angular treats them identically in this regard.
Consider this standalone Angular component code snippet:
@Component({
selector: 'app-sample',
template: 'Hello
',
standalone: true
})
export class SampleComponent {}When used in an Angular app, it does not render and shows an error about missing imports. What is the most likely cause?
Think about what Angular modules provide by default and what standalone components need to import explicitly.
Standalone components must explicitly import CommonModule to use common Angular directives. Without it, Angular throws errors about missing directives.