我有下面的代码工作前角10升级,即角8。
@viewChild in @injectable在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移到组件类时,它就正常工作了。那么,除了在component类中,我们还不能使用@viewChild吗??
帮助感激!
发布于 2022-07-06 10:08:40
将@Injectable()替换为@Directive()
https://stackoverflow.com/questions/65344742
复制相似问题