简体   繁体   English

类型'HTMLElement'上不存在属性'contentDocument'

[英]Property 'contentDocument' does not exist on type 'HTMLElement'

I am loading an svg file using Object element and from ts file am trying to read and modify svg(like coloring dynamicaly and creating some svg elements and appending to the existing svg), but am stuck with the below error: Property 'contentDocument' does not exist on type 'HTMLElement' 我正在使用Object元素和ts文件加载一个svg文件我试图读取和修改svg(比如着色dynamicaly并创建一些svg元素并附加到现有的svg),但我遇到了以下错误:属性'contentDocument'确实'HTMLElement'类型不存在

am using Angular 7 我正在使用Angular 7

in app.component.html 在app.component.html中

 <object id="svg1" data="assets/10026_019.svg" type="image/svg+xml" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></object>

in app.component.ts 在app.component.ts中

let obj=document.getElementById('svg1');
    let svg2=obj.contentDocument.querySelector("svg");
 let pt = svg2.createSVGPoint();

actually it is showing error(red line) at "contentDocument", but when I run the application it is working fine, even though error is there. 实际上它在“contentDocument”显示错误(红线),但是当我运行应用程序时它工作正常,即使有错误。 But When I do ng build it is giving problem. 但是,当我构建它时,它会给出问题。

not sure how I can get this error corrected for to build successfully 不确定如何纠正此错误以便成功构建

I got it resolved myself by updating the as below. 我通过更新如下解决了自己。 I have mentioned object type as "any" explicitly. 我已明确提到对象类型为“any”。

let obj: any =document.getElementById('svg1');
    let svg2: any =obj.contentDocument.querySelector("svg");
 let pt = svg2.createSVGPoint();

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

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