0
0
Angularframework~20 mins

Standalone vs module-based decision in Angular - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Standalone Angular Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
When to prefer standalone components in Angular?

Which scenario best justifies using standalone components instead of module-based components in Angular?

AWhen you want to group many components and services together for lazy loading.
BWhen building a small feature that does not need to be reused across multiple modules.
CWhen you need to share components across multiple modules with complex dependencies.
DWhen you want to organize your app into feature modules for better scalability.
Attempts:
2 left
💡 Hint

Think about simplicity and avoiding extra setup for small, isolated components.

component_behavior
intermediate
2:00remaining
Effect of standalone flag on component imports

Given two Angular components, one standalone and one module-based, how does the standalone: true flag affect importing other components or directives?

AStandalone components import dependencies directly in their <code>imports</code> array, while module-based components rely on NgModules to provide dependencies.
BStandalone components cannot import other components or directives, only modules can.
CModule-based components import dependencies directly in their <code>imports</code> array, standalone components rely on NgModules.
DBoth standalone and module-based components import dependencies the same way using NgModules.
Attempts:
2 left
💡 Hint

Consider where dependencies are declared for standalone components versus module-based components.

📝 Syntax
advanced
2:00remaining
Correct syntax for declaring a standalone component

Which of the following Angular component declarations correctly defines a standalone component?

A@Component({ selector: 'app-test', template: '<p>Test</p>', standalone: true }) export class TestComponent {}
B@Component({ selector: 'app-test', template: '<p>Test</p>' }) export class TestComponent {}
C@Component({ selector: 'app-test', template: '<p>Test</p>', standalone: false }) export class TestComponent {}
D@Component({ selector: 'app-test', template: '<p>Test</p>', standalone: 'true' }) export class TestComponent {}
Attempts:
2 left
💡 Hint

Check the type and presence of the standalone property.

lifecycle
advanced
2:00remaining
Lifecycle differences between standalone and module-based components

Which statement about Angular component lifecycle hooks is true when comparing standalone and module-based components?

AModule-based components have additional lifecycle hooks not available in standalone components.
BStandalone components do not support lifecycle hooks like <code>ngOnInit</code>.
CStandalone components have the same lifecycle hooks and behavior as module-based components.
DStandalone components require manual invocation of lifecycle hooks.
Attempts:
2 left
💡 Hint

Think about whether Angular changes lifecycle behavior based on component type.

🔧 Debug
expert
3:00remaining
Why does this standalone component fail to render?

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?

AThe selector name must start with 'app-' to work correctly.
BStandalone components cannot be used without being declared in an NgModule.
CThe <code>standalone</code> property must be set to false for the component to render.
DThe component is missing the <code>imports</code> array to include CommonModule for common directives like <code>ngIf</code> or <code>ngFor</code>.
Attempts:
2 left
💡 Hint

Think about what Angular modules provide by default and what standalone components need to import explicitly.