1

我正在使用新的dom-to-image库,当我尝试在toPng组件内部调用该方法时遇到此错误。

import domtoimage from 'dom-to-image-more';
export class MyComponent {
    @ViewChild('leafletMap') leafletMap: ElementRef;
    
    downloadMap = (): void => {
        //error happens here
        domtoimage.toPng(this.leafletMap.nativeElement).then((img: any) => {
            console.log(img);
        });
    };
}
/* of course this is simplified */

LeafletMap 存在于我的组件 HTML 中,当我记录它时,它包含一个 HtmlNativeElement

4

1 回答 1

3

似乎最新版本的lib存在问题。尝试使用此版本:

"dom-to-image-more": "2.8.0"

我创建了一个有效的StackBlitz,单击下载按钮并查看结果。

于 2021-10-12T12:38:11.757 回答