我正在使用 Angular 来制作 Canvas 对象的深拷贝,并且我得到 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
进行深层复制吗?
最佳答案
使用element.clone()
克隆 DOM 元素——这是 Angular 的 jQuery clone()
版本.
关于javascript - angular.copy 无法复制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26653846/