When I define html2canvas functions in my controller, the alert in html2canvas doesn't get fired and my canvasToImageSuccess function is not executed. Am I missing something here?
In my controller, I have defined html2canvas functions as shown below:
var builderApp = angular.module('builderApp',
['fg', 'ngSanitize', 'ui.bootstrap', 'angularFileUpload', 'textAngular', 'ui.grid', 'ui.grid.pagination']);
builderApp
.run(function ($templateCache) {
$templateCache.put('custom-busy.html',
"<div class=\"cssload-loader\"><div class=\"cssload-inner cssload-one\"></div><div class=\"cssload-inner cssload-two\"></div><div class=\"cssload-inner cssload-three\"></div></div>"
);
});
builderApp.controller('builderCtrl', function ($scope, formSchema, formData, $http, $filter) {
// Function to convert canvas to image
$scope.canvasToImageSuccess = function (canvas) {
// code for converting canvas to PDF with jsPDF
};
// Function to create PDF from a given source
$scope.createPDF = function () {
var source = $("#formData").html();
try{
// Attempting to use html2canvas library to render HTML to canvas
html2canvas(source, {
onrendered: function (canvas) {
alert('rendered');
$scope.canvasToImageSuccess(canvas);
}
});
}
catch(e)
{
var x = e;
}
}
Despite being able to call the createPDF function from the UI, the alert in html2canvas is not firing. Additionally, I attempted to inject html2canvas using
global.html2canvas = require("html2canvas");
, but this approach did not work. Console does not show any errors.