angular.copy无法复制对象

时间:2014-10-30 13:08:40

标签: javascript angularjs canvas

我正在使用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是否制作了深层副本?

1 个答案:

答案 0 :(得分:1)

使用element.clone()克隆DOM元素 - 它是Angular的jQuery clone()版本。