I have converted jade to html and I show the preview in a popup in my AngularJS app using jade.js. The jade can be edited in a textarea and I have a preview button too.
The problem is when the user misses something in jade console error is shown with proper message and line number.
I want to show this error in popup and not in console.
I have tried something like below in controller but it does not seem to work:
$scope.emailShowPreview = function() {
$scope.locals = $scope.variables_for_email_preview;
window.onerror = function myErrorHandler(err, url, line) {
alert("Error", err);
return false; // so you still log errors into console
}
try {
var jadeFunc = jade.compile($scope.editFileds.body);
} catch {
window.onerror();
}
// compile jade template to html
// console error happens below
$scope.templateFunc = jade.compile($scope.editFileds.body);
$scope.compiledHtml = $scope.templateFunc($scope.locals);
var modalInstance = $modal.open({
scope: $scope,
templateUrl: '../../views/email-preview-popup.html',
backdrop: 'static',
});
$scope.close = function() {
modalInstance.dismiss('cancel');
};
};
I referred below page too but a bit confused :-
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror