1

I am using angular to make a deep copy of a canvas object, and I am getting 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)

Any thoughts? Can angular.copy copy DOM elements?

UPDATE: use angular.element.clone I tried using angular.element.clone, the problem with that is that it seems that it doesnt make a deep copy, I have the following:

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)

When I am changing the imgObj this also affects the clonedImg and changes the clonedCanvas, I want somehow to keep the original information. Is angular.element.clone make a deep copy?

Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133

1 Answers1

1

Use element.clone() to clone DOM elements -- it's Angular's version of jQuery clone().

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
  • This will probably not copy the content of canvas, only the element. –  Oct 30 '14 at 13:22
  • although it copies the element, as I can see that is not a deep copy, its more reference. – Avraam Mavridis Oct 30 '14 at 13:22
  • That's a [separate question](http://stackoverflow.com/questions/3318565/any-way-to-clone-html5-canvas-element-with-its-content). You ordinarily do a deep copy with [`.clone(true,true)`](http://api.jquery.com/clone) – Blazemonger Oct 30 '14 at 13:25