angular camera directive

前端之家收集整理的这篇文章主要介绍了angular camera directive前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import { Directive,ElementRef,Renderer } from '@angular/core';
@Directive({
    selector: '[camera]'
})
export class CameraDirective {
    private video: HTMLVideoElement;
    constructor(private elem: ElementRef,private renderer: Renderer) {
        this.video = elem.nativeElement;
        // renderer.setElementStyle(video,'backgroundColor','red');
}
    public ngAfterViewInit() {
        if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
            navigator.mediaDevices.getUserMedia({ video: true })
                .then((stream) => {
                    this.video.src = window.URL.createObjectURL(stream);
                    this.video.play();
                });
        }

    }
}

猜你在找的Angularjs相关文章