我有一个Ionic2应用程序,它的ParentComponent调用ChildComponent@ViewChild方法来启动多个ChildComponent。其中一个ChildComponentsget在View中使用不同的参数实例化了两次,如下所示:在离线/在线设备状态更改后,我调用ChildComponent的方法来更新它返回的项目列表。@ViewChild(ChildComponent)childComponent:ChildComponent;ngOnInit():void{this.networkService.connectSubscription(()=>{this.c
我想使用多个IonicSlides我动态添加的。但是我不能使用@viewChild。请提出解决此问题的方法。Template.html://somecode组件.ts:@ViewChild('slides')slides:QueryList;....ngAfterViewInit(){setTimeout(()=>{alert(this.slides.toArray());//thislineriseerror},3000);}错误:_this.slides.toArrayisnotafunction 最佳答案 使用@ViewChi
这是我的代码,提示无法读取未定义的属性标题。父组件import{Child}from'./child.component';@Component({selector:'parent',})exportclassParentComponetimplementsOnInit,AfterViewInit{constructor(){}@ViewChild(Child)child:Child;ngAfterViewInit(){console.log("checkdata",this.child.title)}}子组件是。@Component({selector:'child',})expor
简介本文将向您介绍Angular的ViewChild装饰器。在某些情况下,您可能希望从父组件类中访问指令、子组件或DOM元素。ViewChild装饰器返回与给定指令、组件或模板引用选择器匹配的第一个元素。先决条件如果您想要跟随本教程进行操作:考虑安装@angular/cli。使用@angular/cli创建一个新项目,以测试ViewChild在其中的功能。本教程已经验证过可以在@angular/corev13.0.2和@angular/cliv13.0.3下使用。使用ViewChild与指令ViewChild使得访问指令成为可能。假设您有一个SharkDirective。该指令将查找具有属性a