Angular 4 找不到名称 'ViewChild'

标签 angular find viewchild

我有这个奇怪的错误,没有发现任何类似的东西.. 我在我的网站上使用 ng2-canvas-whiteboard 组件作为绘图 Canvas ,一切正常,除非我尝试使用以下方法获取对该 Canvas 的引用:

@ViewChild('canvasWhiteboard') canvasWhiteboard: CanvasWhiteboardComponent;

正如官方文档所建议的,我收到了这个错误:

Failed to compile.

e:/frontend/src/app/components/user/dashboard/dashboard.component.ts (15,2): Cannot find name 'ViewChild'.

有什么建议吗?谢谢

最佳答案

使用前忘记导入ViewChild

import { ViewChild } from '@angular/core'

关于Angular 4 找不到名称 'ViewChild',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46816682/

相关文章:

excel - 在用户定义的函数中使用 .find 方法

java - 玩!框架: using find() model method on a collection

angular - 模板解析错误 : Reference "#XXX" is defined several times in angular

javascript - Angular 2路由器无需重新加载即可更改网址

angular - 在 Angular2 中安装 FileReaderSync

安卓。按标签查找 View

Angular 2 - Beta 16 @ViewChild,loadNextToLocation 试图将一个组件动态加载到另一个组件中?

angularjs - Angular2 View Child未定义错误

Angular 2路由器导航功能不起作用

css - Angular2 模块级样式表