angular - 我们可以在Angular10的@Injectable服务中使用@viewChild吗
问题描述
我有以下代码在 Angular 10 升级之前工作,即 Angular 8。
@injectable 中的 @viewChild 在 Angular8 中工作,但在 Angular10 中没有任何原因?
下面的代码是示例(下面是我现有代码的外观):
@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 移动到组件类时,它工作正常。有什么理由我们不能使用 @viewChild 除了在组件类中吗?
帮助赞赏!
解决方案
推荐阅读
- c++11 - lambda 函数回调返回错误:C++ 没有合适的从到的转换函数存在
- c# - C# 扩展在控制台应用程序中工作,但在 MVC Web 应用程序中不工作。我错过了什么吗?
- javascript - 如何监听来自 GLTF 模型的纹理是否已加载并显示?三.js
- c# - 如何在 C# 中将 [part1|part2] 转换为仅 part1
- flutter - Dart:有没有不使用 Dart 的 split 方法将字符串拆分成句子的方法?
- php - DomPDF 删除页脚中的多余空间
- scala - Scala 中的模式转换
- vba - Powerpoint 插件:如何创建可下载的插件来修改功能区和调用宏?
- android - 从 Uri 创建 DocumentFile
- c# - 向我的 Xamarin 应用程序聊天添加实时功能会引发 System.InvalidOperationException