Sunday, October 5, 2025
HomeLanguagesAngularAngular Cannot find name ‘ViewChild’

Angular Cannot find name ‘ViewChild’

Error cannot find name ViewChild in angular; Through this tutorial, we will find a solution for error cannot find ViewChild in angular applications.

And we can also use this solution with angular versions like angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, and angular 14 to resolve error cannot find ViewChild module.

Angular Cannot find name ‘HttpParams’

Now, we can see the solution to error cannot find the name ViewChild in angular; is as follow:

First of all, import ViewChild from @angular/core from npm package; is as follows:

import { ViewChild } from '@angular/core';

Let’s see the example of how to import ViewChild from @angular/core from npm package; is as follows:

import { Component, VERSION, ViewChild, ElementRef } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent {
  name = "Angular " + VERSION.major;
  
  @ViewChild("myDomeElem", { static: true }) myDomeElem: ElementRef;
  
  ngOnInit() {
    console.log(this.myDomeElem);
    this.myDomeElem.nativeElement.innerHTML = "Changed Dom Element Value";
  }
  
  ngAfterViewInit() {
    console.log(this.myDomeElem);
  }
}

Conclusion

Through this tutorial, we have found a solution for the ‘error cannot find ViewChild in angular applications’ and fixed this error as well.

Recommended Tutorials

RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6706 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6823 POSTS0 COMMENTS
Ted Musemwa
7089 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6779 POSTS0 COMMENTS