【发布时间】:2014-12-26 13:03:42
【问题描述】:
我正在使用 Angular 制作画布对象的深层副本,我收到了 Uncaught InvalidStateError: Failed to read the 'selectionDirection' property from 'HTMLInputElement': The input element's type ('checkbox') does not support selection.
canvas = document.getElementById('workercanvas')
canvas.width = cfg.labelsImage.width
canvas.height = cfg.labelsImage.height
ctx = canvas.getContext('2d')
clonedCanvas = null
if clonedCanvas is null
clonedCanvas = angular.copy(canvas)
有什么想法吗? angular.copy 可以复制 DOM 元素吗?
更新:使用 angular.element.clone 我尝试使用 angular.element.clone,问题是它似乎没有进行深层复制,我有以下内容:
imgObj = new Image(imgWidth, imgHeight)
imgObj.onload = ->
ctx.drawImage(imgObj, 0, 0, imgWidth, imgHeight)
if clonedCanvas is null
clonedCanvas = angular.element.clone(canvas)
clonedImg = angular.element.clone(imgObj)
clonedCanvasContext = clonedCanvas.getContext('2d')
clonedCanvasContext.drawImage(clonedImg, 0, 0, imgWidth, imgHeight)
当我更改 imgObj 时,这也会影响 clonedImg 并更改 clonedCanvas,我想以某种方式保留原始信息。 angular.element.clone 做深拷贝吗?
【问题讨论】:
-
Can angular.copy copy DOM elements?。没有。 -
@dfsq 有什么建议的解决方案吗?
-
你需要克隆 DOM 节点,而不是简单的 JS 对象。请参阅@Blazemonger 的上述评论。
-
@Blazemonger 谢谢!效果很好。
标签: javascript angularjs canvas