Docsity

Certified Angular 2 Developer Practice Exam, Exams of Technology

Toggle sidebar
bg1
Certified Angular 2 Developer Practice Exam
Question 1. What decorator is used to define an Angular component?
A) @Injectable()
B) @Component()
C) @NgModule()
D) @Directive()
Answer: B
Explanation: The @Component() decorator is used to define metadata for Angular components,
specifying their selector, template, and styles.
Question 2. Which file typically contains the root module of an Angular application?
A) main.ts
B) app.component.ts
C) app.module.ts
D) index.html
Answer: C
Explanation: The root module, AppModule, is usually declared in app.module.ts, where imports,
declarations, and bootstrap configuration occur.
Question 3. What does the selector property in @Component metadata define?
A) The component’s template location
B) The component’s CSS styles
C) The HTML tag used to instantiate the component
D) The module for the component
Answer: C
Explanation: The selector property defines the custom HTML tag that Angular uses to render the
component.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53

Partial preview of the text

Download Certified Angular 2 Developer Practice Exam and more Exams Technology in PDF only on Docsity!

Question 1. What decorator is used to define an Angular component? A) @Injectable() B) @Component() C) @NgModule() D) @Directive() Answer: B Explanation: The @Component() decorator is used to define metadata for Angular components, specifying their selector, template, and styles. Question 2. Which file typically contains the root module of an Angular application? A) main.ts B) app.component.ts C) app.module.ts D) index.html Answer: C Explanation: The root module, AppModule, is usually declared in app.module.ts, where imports, declarations, and bootstrap configuration occur. Question 3. What does the selector property in @Component metadata define? A) The component’s template location B) The component’s CSS styles C) The HTML tag used to instantiate the component D) The module for the component Answer: C Explanation: The selector property defines the custom HTML tag that Angular uses to render the component.

Question 4. Which CLI command generates a new Angular component? A) ng add B) ng generate service C) ng generate component D) ng serve Answer: C Explanation: ng generate component (or ng g c) is the Angular CLI command to scaffold a new component. Question 5. What is the purpose of TypeScript in Angular development? A) To style components B) To provide strong typing and object-oriented features C) To manage routing D) To optimize images Answer: B Explanation: TypeScript adds strong typing, interfaces, classes, and decorators, making Angular development more robust and maintainable. Question 6. In package.json, which section lists the libraries used only for development? A) dependencies B) devDependencies C) scripts D) engines Answer: B

D) ngAfterViewInit Answer: B Explanation: ngOnInit is invoked after Angular has set all data-bound properties, suitable for initialization logic. Question 10. What does the @Input() decorator enable in Angular? A) Parent to child data binding B) Child to parent data emission C) Registering services D) Defining routes Answer: A Explanation: @Input() allows a component to receive data from its parent, facilitating parent-to-child communication. Question 11. Which Angular lifecycle hook is used to detect changes to input properties? A) ngOnInit B) ngOnChanges C) ngDoCheck D) ngAfterContentInit Answer: B Explanation: ngOnChanges is called whenever a data-bound @Input property changes, providing SimpleChanges. Question 12. What is the correct syntax for interpolation in Angular templates? A) [data] B) (data)

C) {{ data }} D) $data$ Answer: C Explanation: Interpolation uses double curly braces {{ expression }} to display component data in templates. Question 13. Which binding syntax sets a property of an HTML element from component data? A) {property} B) [property] C) (property) D) #property Answer: B Explanation: Property binding uses square brackets [property]="expression" to bind data to element properties. Question 14. What is the purpose of event binding in Angular? A) To update styles dynamically B) To execute code in response to user events C) To format dates D) To define routes Answer: B Explanation: Event binding uses (event)="handler()" syntax to react to user interactions like clicks. Question 15. Which directive allows for two-way data binding in Angular? A) *ngIf B) [ngClass]

C) *ngIf D) *ngFor Answer: B Explanation: [ngClass] binds CSS classes to an element based on an expression. Question 19. What is required to create a custom attribute directive? A) Extending Component B) Implementing PipeTransform C) Using @Directive() decorator D) Using @Injectable() Answer: C Explanation: Custom attribute directives are created with the @Directive() decorator and a selector. Question 20. Which built-in pipe formats a value as currency? A) DecimalPipe B) CurrencyPipe C) DatePipe D) PercentPipe Answer: B Explanation: CurrencyPipe formats numbers as currency, allowing specification of currency code and digits. Question 21. How can you apply multiple pipes to a value in Angular? A) Separate by commas B) Chain pipes using the | operator

C) Nest pipes in brackets D) Use semicolons Answer: B Explanation: Pipes are chained using the | symbol, applying them in sequence to a value. Question 22. What interface must a custom pipe implement? A) OnInit B) PipeTransform C) Injectable D) Directive Answer: B Explanation: Custom pipes implement the PipeTransform interface, which defines the transform method. Question 23. In Angular’s DI system, what is an injector responsible for? A) Routing requests B) Compiling templates C) Providing instances of services D) Formatting data Answer: C Explanation: Injectors manage and deliver instances of services to components and other services. Question 24. What does the providedIn: 'root' option in @Injectable() mean? A) Service is available only in the current module B) Service is a singleton at the app level

C) Use @Component() D) Add to app.module.ts only Answer: B Explanation: Providing a service in the module’s providers array limits its scope to that module. Question 28. Which array in @NgModule configures the components, directives, and pipes belonging to the module? A) imports B) exports C) declarations D) providers Answer: C Explanation: The declarations array lists all components, directives, and pipes that belong to the module. Question 29. What is a feature module in Angular? A) The root application module B) A module dedicated to a specific functionality C) The shared module D) The app routing module Answer: B Explanation: Feature modules encapsulate related functionality, keeping code organized and maintainable. Question 30. What should be included in a shared module? A) Only services

B) Reusable components, directives, and pipes C) Only routing configuration D) Only feature-specific components Answer: B Explanation: Shared modules house reusable elements used across multiple feature modules. Question 31. What is the main advantage of lazy loading modules? A) Faster compilation B) Reduced initial bundle size and improved load time C) Easier debugging D) Automatic error handling Answer: B Explanation: Lazy loading loads modules only when needed, optimizing initial app performance. Question 32. Which property in a route configuration specifies the component to render? A) path B) children C) component D) canActivate Answer: C Explanation: The component property assigns which component should be instantiated for the route. Question 33. What is the purpose of <router-outlet> in Angular templates? A) Displaying forms B) Rendering routed components

B) Using ActivatedRoute service C) With [routerLink] D) By ngModel Answer: B Explanation: The ActivatedRoute service provides access to route parameters and query parameters within the component. Question 37. How does Angular handle query parameters in routes? A) Using @Output() B) By reading the queryParams property from ActivatedRoute C) Using [ngClass] D) With *ngFor Answer: B Explanation: ActivatedRoute exposes queryParams, which can be subscribed to for accessing query parameters. Question 38. What is a child route in Angular? A) A route with a parent module B) A route nested under another route C) A route with query parameters D) A route with a guard Answer: B Explanation: Child routes are nested in the route configuration, allowing for hierarchical routing structures. Question 39. Which guard can be used to prevent unauthorized access to a route?

A) CanActivate B) CanDeactivate C) Resolve D) OnInit Answer: A Explanation: CanActivate determines whether a route can be activated based on custom logic, such as authentication. Question 40. What does a Resolve guard do in Angular routing? A) Prevents route activation B) Fetches data before navigation completes C) Handles form validation D) Defines child routes Answer: B Explanation: Resolve guards load data before the route activates, ensuring necessary data is available. Question 41. Which guard prevents users from leaving a route if a condition is not met? A) CanActivate B) CanDeactivate C) Resolve D) OnDestroy Answer: B Explanation: CanDeactivate guards block navigation away from a route, useful for unsaved changes in forms. Question 42. What module must be imported to use template-driven forms?

B) ReactiveFormsModule C) HttpClientModule D) BrowserModule Answer: B Explanation: ReactiveFormsModule provides API for managing reactive form controls and groups. Question 46. Which class is used to represent a single control in a reactive form? A) FormGroup B) FormControl C) FormArray D) ControlValueAccessor Answer: B Explanation: FormControl represents a single input element’s value and validation. Question 47. How do you create a group of controls in reactive forms? A) Use FormGroup B) Use FormControl C) Use FormArray D) Use ngModel Answer: A Explanation: FormGroup is used to group multiple controls together in reactive forms. Question 48. Which function is used to implement custom synchronous validators? A) validate() B) validatorFn()

C) checkValid() D) transform() Answer: B Explanation: Custom synchronous validators are created by implementing a validatorFn function. Question 49. What is the purpose of FormArray in reactive forms? A) To store form metadata B) To manage an array of controls dynamically C) To style form elements D) To handle routing Answer: B Explanation: FormArray allows dynamic addition and removal of controls, useful for lists. Question 50. Which module provides HttpClient for REST API communication? A) FormsModule B) HttpClientModule C) RouterModule D) CommonModule Answer: B Explanation: HttpClientModule enables HTTP requests to RESTful APIs from Angular services. Question 51. What method of HttpClient is used for retrieving data? A) post() B) get() C) put()

D) switchMap Answer: C Explanation: The map operator transforms each value emitted by the Observable according to a given function. Question 55. What does the async pipe do in Angular templates? A) Synchronizes data automatically B) Subscribes to Observables and displays their emitted values C) Validates forms D) Handles HTTP requests Answer: B Explanation: The async pipe subscribes to Observables, updating the view with emitted values and handling unsubscription automatically. Question 56. What is a Subject in RxJS? A) An HTTP request B) A multicast Observable C) A form control D) A route guard Answer: B Explanation: A Subject is a multicast Observable that can emit values to multiple observers. Question 57. Which RxJS class provides both the current value and the ability to subscribe? A) Subject B) BehaviorSubject C) ReplaySubject

D) Observable Answer: B Explanation: BehaviorSubject holds the latest value and emits it to new subscribers immediately. Question 58. Which RxJS operator is commonly used for error handling in HTTP requests? A) map B) catchError C) filter D) debounceTime Answer: B Explanation: catchError intercepts errors in Observable streams, enabling custom error handling. Question 59. What is the role of the OnPush change detection strategy? A) Checks for changes on every event loop B) Optimizes performance by checking only when input properties change C) Detects errors in routing D) Handles HTTP requests Answer: B Explanation: OnPush change detection triggers checks only for input changes or events, improving performance. Question 60. How does trackBy optimize *ngFor loops? A) By filtering data B) By tracking item identity to minimize DOM manipulation C) By mapping values