HTML文件:
组件.ts文件:
import { Component, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
@Component({
selector: 'app-video-slideshow',
templateUrl: './video-slideshow.component.html',
styleUrls: ['./video-slideshow.component.css']
})
export class VideoSlideshowComponent implements AfterViewInit {
@ViewChild('videoElement', { static: false }) videoElement: ElementRef;
ngAfterViewInit(){
this.video = this.videoElement.nativeElement;
}
// Your other code here
}
HTML文件:
组件.ts文件:
playVideo(videoId){
let video = document.getElementById('video-'+videoId) as HTMLVideoElement;
video.play();
}