Angular uses modules to group related parts of an application. What is the main benefit of this organization?
Think about how loading parts of an app only when needed can help performance.
Modules let Angular load parts of the app lazily, which means only loading code when the user needs it. This speeds up the initial load and keeps the app organized.
Consider an Angular component declared in two different modules. What will Angular do when compiling?
Think about Angular's rule for component declarations in modules.
Angular requires each component to be declared in exactly one module. Declaring it in multiple modules causes a compilation error.
Which option shows the correct way to define an Angular module with one component and one service?
Look for correct property names and array usage in @NgModule decorator.
The @NgModule decorator requires arrays for declarations, providers, and bootstrap. Property names must be exact: declarations, providers, bootstrap.
Given this module code, why does Angular fail to bootstrap?
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; @NgModule({ declarations: [AppComponent], imports: [BrowserModule], providers: [], bootstrap: [AppComponent] }) export class AppModule {} // In app.component.ts import { Component } from '@angular/core'; @Component({ selector: 'app-root', template: '<h1>Welcome</h1>' }) export class AppComponent {}
Check how Angular bootstraps the app and what it looks for in the HTML.
Angular bootstraps the component with selector 'app-root'. If index.html does not have <app-root>, Angular cannot attach the app, causing a runtime error.
If a service is provided in a feature module, what happens to its instance when the module is lazy loaded multiple times?
Think about how Angular creates service instances when modules are loaded lazily multiple times.
When a module is lazy loaded multiple times, each load creates a new injector. Services provided in that module get new instances scoped to each injector.