首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我们可以在Angular10中使用@Injectable服务中的@viewChild吗

我们可以在Angular10中使用@Injectable服务中的@viewChild吗
EN

Stack Overflow用户
提问于 2020-12-17 16:37:03
回答 1查看 680关注 0票数 1

我有下面的代码工作前角10升级,即角8。

@viewChild in @injectable在Angular8中工作,但在Angular10中却没有工作,有什么原因吗?

下面的代码是示例(下面是我现有代码的外观):

代码语言:javascript
复制
@Injectable()
export abstract class DetailBaseComponent
  extends BaseComponent {

/**
   * Reference to the child modal component
   */
  @ViewChild(ModalComponent)
  modal: ModalComponent;

findDetail(){
  console.log(this.modal); //undefined
  this.modal.showModal = true;// error
}

但是,当我将@viewChild从@Injectable移到组件类时,它就正常工作了。那么,除了在component类中,我们还不能使用@viewChild吗??

帮助感激!

EN

回答 1

Stack Overflow用户

发布于 2022-07-06 10:08:40

将@Injectable()替换为@Directive()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65344742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档