Bird
0
0

Which of the following is the correct syntax to import @ViewChild in an Angular component?

easy📝 Syntax Q3 of 15
Angular - Component Interaction
Which of the following is the correct syntax to import @ViewChild in an Angular component?
Aimport { ViewChild } from '@angular/core';
Bimport { ViewChild } from '@angular/common';
Cimport { ViewChild } from '@angular/forms';
Dimport { ViewChild } from '@angular/platform-browser';
Step-by-Step Solution
Solution:
  1. Step 1: Identify the Angular package for core decorators

    @ViewChild is part of Angular's core package, so it must be imported from '@angular/core'.
  2. Step 2: Verify other options

    @angular/common, @angular/forms, and @angular/platform-browser do not export @ViewChild.
  3. Final Answer:

    import { ViewChild } from '@angular/core'; -> Option A
  4. Quick Check:

    @ViewChild import source = '@angular/core' [OK]
Quick Trick: Always import @ViewChild from '@angular/core' [OK]
Common Mistakes:
  • Importing @ViewChild from wrong Angular packages
  • Forgetting to import @ViewChild at all

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes