如何将JavaScript代码document.queryselector转换为Angular9?

发布于 2025-02-13 06:04:24 字数 358 浏览 2 评论 0原文

我有JavaScript代码编写的代码为let input = document.queryselector(“#input”);> 我

input.addEventListener('click', function() {
    canvas.getContext('2d').drawImage(input, 0, 0, canvas.width, canvas.height);
    let image_data_url = canvas.toDataURL('image/jpeg');
});

想用Angular编写此代码,如何在Angular9项目中转换和使用此代码,任何人请帮助我

I have code which is written in JavaScript code as let input= document.querySelector("#input");
and

input.addEventListener('click', function() {
    canvas.getContext('2d').drawImage(input, 0, 0, canvas.width, canvas.height);
    let image_data_url = canvas.toDataURL('image/jpeg');
});

I want to write this code in angular how can I convert and use this code in angular9 project anyone please help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那伤。 2025-02-20 06:04:24

最好的方法就是这样:

<input (click)="clickOnMyInput($event)">

在您的.TS文件中

clickOnMyInput(e){
    this.canvas.getContext('2d').drawImage(e.target, 0, 0, this.canvas.width, this.canvas.height);
    let image_data_url = this.canvas.toDataURL('image/jpeg');
}

the best way to do it is like this:

<input (click)="clickOnMyInput($event)">

and in your .ts file

clickOnMyInput(e){
    this.canvas.getContext('2d').drawImage(e.target, 0, 0, this.canvas.width, this.canvas.height);
    let image_data_url = this.canvas.toDataURL('image/jpeg');
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文