gpt4 book ai didi

javascript - 在 Angular 中使用 ngFor 创建织物 Canvas

转载 作者:行者123 更新时间:2023-11-28 03:56:47 25 4
gpt4 key购买 nike

我在 Angular 4 中使用 Fabric.js。我成功地在组件内创建了一个 Canvas 并成功在其上绘图。

我使用了 this.canvas = new Fabric.Canvas('canvas1',{});this.canvas.add(New Fabric.Rect...) 在我的 file.ts 中

然后我尝试生成多个 Canvas ,我在 Canvas 元素上使用了 *ngFor 并设法将 id 属性设置为 canvas1、canvas2...

现在相同的代码 this.canvas = new Fabric.Canvas('canvas1',{}); ... a 不再工作,就好像没有 id = canvas1 的 Canvas 一样。当我检查 dom 时,该元素就在那里。

*ngFor 破坏了这个或者我错过了一些东西?

最佳答案

我发现了问题,绘图代码是在 View 准备好之前执行的,在ngFor执行之前。

解决方案是在 View 准备好后使用 ngAfterViewInit()

执行代码

关于javascript - 在 Angular 中使用 ngFor 创建织物 Canvas ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47498960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com