简体   繁体   English

Angular 7 在纯JS上使用dom元素

[英]Angular 7 use dom element on pure JS

Hi im using webcamJS library on my Angular project (because i need to use webcam on IE 11) , this library has a function called "attach" and it receive the ID of the element where the image is displayed, when i pass my div id it is not recognized in the library, if i check in the browser inspector, the div id is correct.嗨,我在我的 Angular 项目上使用 webcamJS 库(因为我需要在 IE 11 上使用网络摄像头) ,这个库有一个名为“attach”的 function,它接收显示图像的元素的 ID,当我传递我的 div id它在库中无法识别,如果我在浏览器检查器中检查,则 div id 是正确的。

there is my html有我的 html

<div  #my_camera ></div>   <!--div  id="my_camera" ></div -->   

and my Ts which uses pure JS function和我的 Ts 使用纯 JS function

Webcam.attach("#my_camera");

i have tried without # but is the same.我试过没有#,但结果是一样的。

the error on library is "Could not locate DOM element to attach to."库上的错误是“无法找到要附加的 DOM 元素”。

What is the best way to use JS in my TS?在我的 TS 中使用 JS 的最佳方式是什么? Why the JS is not recognizing the ID of my DIV?为什么 JS 无法识别我的 DIV 的 ID?

Regards.问候。

Try this尝试这个

HTML: HTML:

<div  #my_camera ></div>

TS: TS:

@ViewChild('my_camera') myCamaraView : ElementRef;
Webcam.attach(myCamaraView);

For more info check this: https://www.techiediaries.com/angular-elementref/有关更多信息,请查看: https://www.techiediaries.com/angular-elementref/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM