I parsed a bunch of email messages from a server, and I would now like to display them on a webpage. I got their HTML contents and I figured an IFrame was the easiest way to show the emails as they were meant to be shown.
However,
<iframe srcdoc="{{ email.html }}" frameborder="0"></iframe>
Gives me the following AngularJS error:
Error: [$interpolate:interr] Can't interpolate: {{ email.html }}
Error: [$sce:unsafe] Attempting to use an unsafe value in a safe context.
I have been searching for a way to do this, tried disabling $sce as a test, but that didn't work either. It's just a test project and the data I'm getting is safe, I just need it for a POC.
I did this now in my controller:
var iframeDocument = document.querySelector('#myiframe').contentWindow.document;
var content = $scope.email.html;
iframeDocument.open('text/html', 'replace');
iframeDocument.write(content);
iframeDocument.close();
That works, but I'd still prefer to do it through data-binding, if there's a solution? Thanks.
$('#myiframe').attr('srcdoc', $scope.email.html);but that didn't really work out either.$scope.emailHtml = $sce.trustAsHtml($scope.email.html), but there is nong-srcdoc-bind-htmlwhich I think is the other piece of this puzzle (checkoutng-bind-html)