Q. Which service is used to interact with the browser's URL in Angular?

  • (A) HttpClient
  • (B) Router
  • (C) Location
  • (D) DomSanitizer
πŸ’¬ Discuss
βœ… Correct Answer: (C) Location
Explanation: Location service allows interaction with the browser's URL.

Q. What does Angular's DomSanitizer help with?

  • (A) Performance tuning
  • (B) Animation optimization
  • (C) Security against XSS attacks
  • (D) Router configuration
πŸ’¬ Discuss
βœ… Correct Answer: (C) Security against XSS attacks
Explanation: DomSanitizer helps protect against Cross-Site Scripting (XSS) by sanitizing potentially unsafe inputs.

Q. Which pipe is used to transform text to uppercase?

  • (A) capitalize
  • (B) uppercase
  • (C) textFormat
  • (D) stringify
πŸ’¬ Discuss
βœ… Correct Answer: (B) uppercase
Explanation: The `uppercase` pipe transforms text to all uppercase letters.

Q. How can you disable a button based on form validation status?

  • (A) [disabled]='form.valid'
  • (B) [disabled]='!form.valid'
  • (C) [disable]='form.valid'
  • (D) [disable]='!form.invalid'
πŸ’¬ Discuss
βœ… Correct Answer: (B) [disabled]='!form.valid'
Explanation: You disable the button when the form is invalid using `!form.valid`.

Q. Which Angular CLI command is used to serve the application?

  • (A) ng build
  • (B) ng deploy
  • (C) ng serve
  • (D) ng start
πŸ’¬ Discuss
βœ… Correct Answer: (C) ng serve
Explanation: `ng serve` compiles and serves the app in development mode.

Q. Which module is needed to use Angular's reactive forms?

  • (A) FormsModule
  • (B) ReactiveFormsModule
  • (C) HttpClientModule
  • (D) CommonModule
πŸ’¬ Discuss
βœ… Correct Answer: (B) ReactiveFormsModule
Explanation: `ReactiveFormsModule` is required for using reactive forms in Angular.

Q. What happens when you use *ngIf and *ngFor on the same element?

  • (A) Both directives work simultaneously
  • (B) Only *ngIf works
  • (C) Error occurs
  • (D) Angular merges both
πŸ’¬ Discuss
βœ… Correct Answer: (C) Error occurs
Explanation: Angular does not allow multiple structural directives on the same element directly.

Q. What is a HostListener in Angular?

  • (A) Listens to events on child components
  • (B) Subscribes to observables
  • (C) Listens to DOM events on the host element
  • (D) Captures global events only
πŸ’¬ Discuss
βœ… Correct Answer: (C) Listens to DOM events on the host element
Explanation: @HostListener decorates methods to listen to DOM events on the host element.

Q. Which command builds the Angular app for production?

  • (A) ng run
  • (B) ng prod
  • (C) ng build --prod
  • (D) ng serve --prod
πŸ’¬ Discuss
βœ… Correct Answer: (C) ng build --prod
Explanation: `ng build --prod` compiles and optimizes the app for production.

Q. What does the async pipe handle automatically?

  • (A) Form validation
  • (B) DOM rendering
  • (C) Subscription and unsubscription
  • (D) Routing and guards
πŸ’¬ Discuss
βœ… Correct Answer: (C) Subscription and unsubscription
Explanation: The async pipe automatically subscribes to an Observable and unsubscribes when the component is destroyed.