I have this strange error and didn't find anything similar to it .. I'm using ng2-canvas-whiteboard component for a drawing canvas on my website, everything's working perfectly except when i try to get reference to that canvas using :
@ViewChild('canvasWhiteboard') canvasWhiteboard: CanvasWhiteboardComponent;
as the official docs suggested, i'm getting this error :
Failed to compile.
e:/frontend/src/app/components/user/dashboard/dashboard.component.ts (15,2): Cannot find name 'ViewChild'.
Any suggestions ? Thank you
ViewChild is used to select an element from component's template while ContentChild is used to select projected content.
The @ViewChild decorator allows us to inject into a component class references to elements used inside its template, that's what we should use it for. Using @ViewChild we can easily inject components, directives or plain DOM elements.
A ViewChild is a component, directive, or element as a part of a template. If we want to access a child component, directive, DOM element inside the parent component, we use the decorator @ViewChild() in Angular.
Working with @ViewChildren is similar to @ViewChild, but the difference between the two is @ViewChildren provides a list of element references rather than returning a single reference. It is used to reference multiple elements. We can then iterate the list of the element referenced by the variable.
You forgot to import ViewChild
before using it
import { ViewChild } from '@angular/core'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With