我收到以下错误,但程序运行正常

angular -  typescript -对象可能是 'null'-LMLPHP

var video = document.querySelector('#camera-stream'),

if(!navigator.getMedia){
        displayErrorMessage("Your browser doesn't have support for the navigator.getUserMedia interface.");
    }
    else{
        // Request the camera.
        navigator.getMedia(
            {
                video: true
            },
            // Success Callback
            function(stream:any){

                // Create an object URL for the video stream and
                // set it as src of our HTLM video element.
                video.src = window.URL.createObjectURL(stream);

                // Play the video element to start the stream.
                video.play();
                video.onplay = function() {
                    showVideo();
                };

            },
            // Error Callback
            function(err:any){
                displayErrorMessage("There was an error with accessing the camera stream: " + err.name, err);
            }
        );

    }

我尝试了in this questions解决方案,但对我不起作用。

该错误的正确解决方法是什么?

最佳答案

尝试转换:

var video = document.querySelector('#camera-stream')

至:
var video = <HTMLVideoElement>document.querySelector('#camera-stream')

关于angular - typescript -对象可能是 'null',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43951090/

10-09 18:42