Angular Web Framework Angular Professional Development 2 — Questions and Answers
Question 1: Which Angular CLI command generates a new library inside an existing workspace?
- ng new my-lib
- ng generate library my-lib (Correct answer)
- ng add my-lib
- ng create library my-lib
Correct answer: ng generate library my-lib
The `ng generate library` command scaffolds a publishable Angular library within the current workspace.
Question 2: What is the primary purpose of Angular's `provideHttpClient()` function introduced in Angular 15+?
- Replace HttpClientModule with a standalone-compatible provider (Correct answer)
- Enable HTTP/2 support in Angular apps
- Provide automatic retry logic for HTTP requests
- Configure CORS headers on outgoing requests
Correct answer: Replace HttpClientModule with a standalone-compatible provider
`provideHttpClient()` is the standalone API equivalent of importing `HttpClientModule`, making it compatible with standalone components.
Question 3: In Angular's signal-based reactivity (Angular 16+), what does `effect()` do?
- Creates a writable signal with an initial value
- Runs a side-effect function whenever its dependent signals change (Correct answer)
- Transforms one signal's value into another derived value
- Schedules a one-time async operation after view init
Correct answer: Runs a side-effect function whenever its dependent signals change
`effect()` registers a reactive side-effect that automatically re-runs whenever any signal it reads emits a new value.
Question 4: Which decorator marks a class as an Angular standalone component without an NgModule?
- @Injectable({ standalone: true })
- @Component({ standalone: true }) (Correct answer)
- @NgModule({ standalone: true })
- @Directive({ standalone: true, selector: 'app-root' })
Correct answer: @Component({ standalone: true })
Setting `standalone: true` in the `@Component` decorator removes the need to declare the component in any NgModule.
Question 5: What does Angular's `APP_INITIALIZER` token enable?
- Lazy-loading root modules before routing starts
- Running async setup tasks before the app fully bootstraps (Correct answer)
- Providing a global error handler during initialization
- Registering service workers at startup
Correct answer: Running async setup tasks before the app fully bootstraps
`APP_INITIALIZER` accepts factory functions that return promises or observables, delaying app bootstrap until they resolve.
Question 6: Which Angular CDK utility provides accessible focus management for custom overlay components?
- FocusMonitor / FocusTrap (Correct answer)
- OverlayContainer
- Breakpoints
- Platform
Correct answer: FocusMonitor / FocusTrap
`FocusTrap` and `FocusMonitor` from `@angular/cdk/a11y` manage keyboard focus within overlays to satisfy WCAG requirements.
Question 7: What is the correct way to enable strict template type checking across an Angular project?
- Set `"strictTemplates": true` in tsconfig.json
- Set `"strictTemplates": true` in angular.json under `architect > build` (Correct answer)
- Add `// @ts-strict` at the top of every template file
- Pass `--strict-templates` flag to every `ng serve` call
Correct answer: Set `"strictTemplates": true` in angular.json under `architect > build`
Strict template type checking is enabled by setting `"strictTemplates": true` inside the `angularCompilerOptions` section of `tsconfig.json`.
Which Angular CLI command generates a new library inside an existing workspace?