我有两个组件,一个 videoComponent 和 videoControlsComponent。video 组件包含一个<video>
元素,并且 video 组件具有一些按钮来操作 videoComponent<video>
元素。
<video controls="{{ controls }}" [src]="streamUrl" #myVideo>
Your browser does not support the video tag or the file format of this video.
</video>
视频组件:
@ViewChild('myVideo') myVideo: any;
public playVideo() {
this.myVideo.nativeElement.play();
}
视频控制组件:
constructor(private videoComponent: VideoComponent) { }
public videoPlay() {
this.videoComponent.playVideo()
}
问题是当我单击按钮时出现以下错误:Cannot read property 'nativeElement' of undefined at VideoControlsComponent
.
但是当我有完全相同的代码但不是在 videoControlsComponent 而是在 videoComponent 中创建按钮时,一切正常。
你能帮帮我吗?