Docsity

Certified Angular 4 Developer Practice Exam, Exams of Technology

Toggle sidebar
bg1
Certified Angular 4 Developer Practice Exam
Question 1. Which metadata property in NgModule is used to specify the components, directives, and
pipes that belong to the module?
A) imports
B) declarations
C) providers
D) exports
Answer: B
Explanation: The declarations array specifies the components, directives, and pipes that are part of the
module.
Question 2. What is the main purpose of the bootstrap array in the NgModule metadata?
A) To provide services
B) To define the root component
C) To import other modules
D) To export reusable components
Answer: B
Explanation: The bootstrap array lists the root component(s) that Angular creates and inserts into the
index.html host web page.
Question 3. Which Angular function is used to bootstrap the root module in a browser environment?
A) bootstrap()
B) platformBrowser()
C) platformBrowserDynamic().bootstrapModule()
D) bootstrapModuleDynamic()
Answer: C
Explanation: platformBrowserDynamic().bootstrapModule(AppModule) is the standard way to
bootstrap the root module in Angular browser applications.
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

Partial preview of the text

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

Question 1. Which metadata property in NgModule is used to specify the components, directives, and pipes that belong to the module? A) imports B) declarations C) providers D) exports Answer: B Explanation: The declarations array specifies the components, directives, and pipes that are part of the module. Question 2. What is the main purpose of the bootstrap array in the NgModule metadata? A) To provide services B) To define the root component C) To import other modules D) To export reusable components Answer: B Explanation: The bootstrap array lists the root component(s) that Angular creates and inserts into the index.html host web page. Question 3. Which Angular function is used to bootstrap the root module in a browser environment? A) bootstrap() B) platformBrowser() C) platformBrowserDynamic().bootstrapModule() D) bootstrapModuleDynamic() Answer: C Explanation: platformBrowserDynamic().bootstrapModule(AppModule) is the standard way to bootstrap the root module in Angular browser applications.

Question 4. What does the imports array in an NgModule configuration specify? A) Components used in the module B) Other modules whose exported classes are needed by component templates in this module C) The initial route D) The main CSS file Answer: B Explanation: The imports array lists other modules whose exported classes are required for the templates in the current module. Question 5. What is the primary difference between a root module and a feature module in Angular? A) Only the root module can import other modules B) The root module is required for every application, feature modules are optional and used to organize related code C) Feature modules are always lazy-loaded D) There is no difference Answer: B Explanation: The root module is essential and bootstraps the application, while feature modules are used for organization and code splitting. Question 6. Which TypeScript feature allows the use of annotations like @Component and @NgModule in Angular? A) Classes B) Interfaces C) Decorators D) Generics Answer: C

Answer: C Explanation: Zone.js patches async operations, allowing Angular to know when to update the view in response to changes. Question 10. Which Angular decorator is required to define a component? A) @NgModule B) @Injectable C) @Component D) @Directive Answer: C Explanation: @Component is used to define an Angular component, specifying its selector, template, and style files. Question 11. What is the function of the selector property in the @Component decorator? A) Defines the path for the component template B) Specifies the directive's CSS selector used in templates C) Sets the default change detection strategy D) Imports styles Answer: B Explanation: The selector property specifies the string that identifies this component in a template. Question 12. How are styles provided to an Angular component using the @Component decorator? A) Using the stylesUrl property B) Using the styleUrls property C) Using the css property D) Using the templateStyles property

Answer: B Explanation: styleUrls is an array property for providing the paths to CSS files for a component. Question 13. What is the correct order of lifecycle hooks executed when a component is created? A) ngOnInit, ngOnChanges, ngDoCheck B) ngOnChanges, ngOnInit, ngDoCheck C) ngDoCheck, ngOnInit, ngOnChanges D) ngOnInit, ngDoCheck, ngOnChanges Answer: B Explanation: The correct order is ngOnChanges (if inputs change), then ngOnInit, and then ngDoCheck. Question 14. Which lifecycle hook is called only once after the first ngOnChanges? A) ngOnInit B) ngAfterViewInit C) ngOnDestroy D) ngAfterContentChecked Answer: A Explanation: ngOnInit is called once after the first ngOnChanges. Question 15. What does the ngOnDestroy lifecycle hook allow you to do? A) Initialize data B) Perform cleanup just before Angular destroys the component C) Detect changes D) Render the view Answer: B

Explanation: Event binding uses parentheses: (event)="handler". Question 19. What is required to use two-way data binding with [(ngModel)] in Angular forms? A) ReactiveFormsModule B) FormsModule C) HttpClientModule D) RouterModule Answer: B Explanation: Two-way data binding using [(ngModel)] requires importing FormsModule. Question 20. Which of the following is an example of a structural directive in Angular? A) [ngClass] B) *ngIf C) [ngStyle] D) [routerLink] Answer: B Explanation: ngIf is a structural directive that conditionally includes or excludes an element. Question 21. What does the asterisk () in *ngIf and *ngFor indicate? A) Event binding B) Attribute binding C) Structural directive shorthand syntax D) Pipe usage Answer: C

Explanation: The asterisk (*) is syntactic sugar indicating a structural directive that modifies the DOM structure. Question 22. How do you provide an alternative template with *ngIf in Angular? A) Using else keyword and a template reference B) Using [else] C) Using (else) D) Using ng-template only Answer: A Explanation: The else keyword, along with a template reference, provides an alternative template to *ngIf. Question 23. Which built-in directive is used to iterate over collections in templates? A) *ngIf B) *ngSwitch C) *ngFor D) [ngClass] Answer: C Explanation: *ngFor is used to iterate over collections and display a template for each item. Question 24. What is the purpose of the trackBy function in *ngFor? A) To sort the list B) To optimize performance by uniquely identifying items C) To filter items D) To group items Answer: B

Explanation: [ngStyle] is used to set inline styles dynamically. Question 28. Which decorator is used to create a custom attribute directive? A) @Pipe B) @Component C) @Directive D) @Injectable Answer: C Explanation: @Directive is used to define a custom directive in Angular. Question 29. What is the role of ElementRef in custom attribute directives? A) Provides a reference to the parent module B) Offers direct access to the DOM element C) Handles HTTP requests D) Manages routing Answer: B Explanation: ElementRef provides access to the DOM element, allowing manipulation within directives. Question 30. Why is Renderer preferred over direct DOM manipulation in Angular directives? A) It's faster B) It ensures cross-platform compatibility and security C) It uses less memory D) It's required by TypeScript Answer: B

Explanation: Renderer allows safe, cross-platform DOM manipulation, avoiding direct access for security and compatibility. Question 31. What is the function of the @HostListener decorator in a directive? A) Injects a service B) Listens to events on the host element C) Binds input properties D) Registers the directive with Angular Answer: B Explanation: @HostListener allows you to listen for events on the host element of a directive. Question 32. How does @HostBinding differ from @HostListener in a directive? A) @HostBinding is used for event handling B) @HostBinding binds a property of the host element to a directive property C) @HostListener changes the template D) @HostListener is for data binding Answer: B Explanation: @HostBinding binds a host element property to a directive property, unlike @HostListener, which is for events. Question 33. How is a service typically defined in Angular? A) Using the @Component decorator B) As a class annotated with @Injectable C) Using @Directive D) With a JSON file Answer: B

Explanation: Providing a service at the root level creates a singleton instance for the entire application. Question 37. What is the effect of providing a service in a component's providers array? A) Singleton instance for the whole app B) New instance for each component instance C) Not available anywhere D) Only available in feature modules Answer: B Explanation: Providing a service at the component level creates a new instance for each component. Question 38. How do you inject a service into a component in Angular? A) Using @Injectable on the component B) By declaring it in the component's template C) By adding it to the component's constructor parameters D) Using @NgModule Answer: C Explanation: Inject services into components via constructor injection. Question 39. What is the default binding syntax for two-way data binding in Angular forms? A) [()] B) {{}} C) [] D) () Answer: A Explanation: [(ngModel)] is the syntax for two-way data binding.

Question 40. Which module must be imported to use template-driven forms? A) HttpClientModule B) CommonModule C) FormsModule D) RouterModule Answer: C Explanation: FormsModule is required for template-driven forms. Question 41. How do you access the state of a form control in template-driven forms? A) Using ReactiveFormsModule B) Using local template variable (e.g., #name="ngModel") C) Using @ViewChild D) Using @Input Answer: B Explanation: Local template variables expose form control state in templates. Question 42. Which built-in validator ensures a form control is not empty? A) minlength B) required C) pattern D) maxLength Answer: B Explanation: The required validator checks that the control is not empty.

A) Using FormControl only B) Using FormGroup C) Using FormArray D) Using Validators Answer: B Explanation: FormGroup manages a group of FormControl instances. Question 47. What is the role of FormBuilder in Angular reactive forms? A) To build services B) To simplify the creation of form controls, groups, and arrays C) To manage HTTP requests D) To configure routing Answer: B Explanation: FormBuilder is a service that streamlines form creation. Question 48. How do you implement a custom synchronous validator in a reactive form? A) By passing a function to the validators array in FormControl B) By using the HTTP client C) By using async-await D) By importing CommonModule Answer: A Explanation: Custom sync validators are functions provided to the validators array. Question 49. What is the difference between synchronous and asynchronous validators? A) Sync validators return Promises; async validators return values

B) Sync validators execute immediately; async validators perform operations like HTTP requests and return Observables or Promises C) Only async validators can be used in reactive forms D) Sync validators are not supported Answer: B Explanation: Sync validators are immediate; async validators handle asynchronous checks using Observables or Promises. Question 50. How can you observe changes to form values in a reactive form? A) Using the valueChanges Observable property on FormGroup or FormControl B) Using ngModel C) Using @ViewChild D) Using @Input Answer: A Explanation: valueChanges emits events when the value of a form control or group changes. Question 51. How is the RouterModule typically configured in an Angular app? A) Via @Component B) Using the forRoot() method with a routes array C) Using @Injectable D) In the providers array Answer: B Explanation: RouterModule.forRoot(routes) configures routing for the application. Question 52. In route configuration, what does the pathMatch: 'full' option do? A) Matches only the beginning of the URL

C) Using @ViewChild D) Using ngModel Answer: A Explanation: ActivatedRoute provides access to route parameters. Question 56. What is the difference between accessing route parameters via snapshot and as an Observable? A) No difference B) Snapshot provides parameters at the time of route creation; Observable allows tracking changes over time C) Snapshot is only for query params D) Observable is not supported Answer: B Explanation: Snapshot is static; Observables allow for changes as navigation occurs. Question 57. How do you access query parameters in a route? A) ActivatedRoute.queryParams B) RouterModule.queryParams C) [routerLink] D) ngModel Answer: A Explanation: ActivatedRoute.queryParams exposes query parameters as an Observable. Question 58. Which route guard is used to prevent navigation to a route unless certain conditions are met? A) CanDeactivate

B) CanActivate C) CanLoad D) CanResolve Answer: B Explanation: CanActivate blocks navigation if its guard logic returns false. Question 59. Which route guard is used to prevent navigation away from a route, such as when there are unsaved changes? A) CanActivate B) CanDeactivate C) CanLoad D) CanResolve Answer: B Explanation: CanDeactivate can prevent leaving a route unless certain conditions are met. Question 60. Which route guard can prevent the loading of a lazy-loaded module? A) CanDeactivate B) CanActivate C) CanLoad D) CanResolve Answer: C Explanation: CanLoad prevents lazy-loaded modules from being loaded unless the guard allows it. Question 61. How is lazy loading implemented in Angular routing? A) By adding the module to the declarations array