angular-canvas-painter icon indicating copy to clipboard operation
angular-canvas-painter copied to clipboard

How to access canvas content in my angular controller?

Open rodrigovallades opened this issue 9 years ago • 4 comments

Hi. Thank you for this great directive.

I was able to integrate it in my project, but I'm having trouble acessing the canvas content in my Angular controller.

I need to convert the canvas to an image and save it in my database via API.

Thank you in advance, Rodrigo

rodrigovallades avatar Dec 09 '15 20:12 rodrigovallades

My actual question is: does the directive expose an angular model of the canvas content, or do I need to take care of that with pure JavaScript?

rodrigovallades avatar Dec 10 '15 11:12 rodrigovallades

Hey, this is not yep implemented. At the moment you have to access the canvas with its id to get the context/image. But there will be an update soon (next few days), which will provides the context in an easier way.

Cherrs Phil

pwambach avatar Dec 11 '15 14:12 pwambach

hi @pwambach, can you give us info on "which will provides the context in an easier way." accessing image data ?

thanks

nenadlazovic avatar Apr 08 '16 12:04 nenadlazovic

Hey, sorry, have been a bit lazy on this one. For now the only option is to pass a custom Id (in the options object) to the canvas and access it with document.getElementById('<customId>') in your controller. From there you can get the context, dataUrl or whatever.

I was thinking about returning the dataUrl as a scope variable on which you can set a watch function in the controller? But I am not sure if this is the best solution.

What do you need from the canvas? the canvas element, context or dataURL? And how do you want to access it.

Another solution could perhaps be a callback which provides the canvas element as parameter.

pwambach avatar Apr 11 '16 09:04 pwambach