So basically i want to manupilate the DOM and replace a canvas tag with an img tag that has a angular variable as attrubute...
I use this line of code:
$("canvas").replaceWith('<img id="editImage" ng-src={{ImageToEdit}}>');
But what ends up beeing inserted is this:
<img id="editImage" ng-src="{{ImageToEdit}}">
The quotes surrounding {{ImageToEdit}} stops angular from realizing that it is part of the scope. Any solution would be greatly appreciated!
Edit: Okey so this is a bit more complicated than I thought... so maby you guys could help me better if I provide some more background:
So lets start with how it looks when the page is loaded:
<img id="editImage" class="edit-image" ng-src="{{ImageToEdit}}">
<button class="btn btn-success" ng-click="previous()">prev</button>
<button class="btn btn-success" onClick="invert()">invert</button>
<button class="btn btn-success" ng-click="next()">next</button>
when previous or next is called the ImageToEdit is changed, but if invert() is called:
function invert(){
img = document.getElementById('editImage');
var newpix = Pixastic.process(img, "invert");
}
Pixastic.process will modify the DOM and change the img tag to a canvas tag (and remove the ng-src attribute)
so when for example next() is called nothing will change... so what i try to do is call a function in next() that returns the data from canvas and turns it back into the original img tag..
$scope.next = function (){
var data = resetCanvasToImgAngGetModifiedData();
$scope.images[$scope.index] = data;
if($scope.index == ($scope.images.length -1)){
$scope.index = 0;
}else{
$scope.index = $scope.index + 1;
}
$scope.ImageToEdit = $scope.images[$scope.index];
}
function resetCanvasToImgAngGetModifiedData(){
var canvas = document.getElementById("editImage");
var dataURL = canvas.toDataURL();
$("canvas").replaceWith('<img id="editImage" class="edit-image" ng-src= {{ImageToEdit}}>');
return dataURL;
}
I do not understand how I am to accomplish this using directives... as the original img tag will be destroyed by Pixastic