I have following HTML with a property binding:
<div [innerHtml]="logOutput"></div>
In my component I add now some content with this line of code
this.logOutput = this.sanitizer.bypassSecurityTrustHtml( this.logOutput + otpStr );
But nevertheless I get this error "SafeValue must use [property]=binding".
Why I get this error? I'm already using property binding! I'm using Angular 5.
Edit: I tried out using a custom pipe inside the HTML and it worked fine, but I want a solution without pipes.
Edit2:
Here my function, where I set the HTML, maybe it helps. A complete working example is not possible, because my app deals with command line tools and output streams (I have Angular in an Electron frame)
this.logStream.on('data', (chunk) => {
let otpStr = chunk.toString();
if (otpStr == '') {
return;
}
otpStr = this.StylePipe(otpStr); // Convert ANSI Styles to HTML with CSS
otpStr = otpStr.replace(/\r?\n/g, '<br />');
otpStr = otpStr.replace(/<br \/><br \/>/g, '<br />');
otpStr = otpStr.replace(/^<br \/>/, '');
otpStr = otpStr.replace(/<br \/>$/, '');
this.logOutput = this.sanitizer.bypassSecurityTrustHtml( this.logOutput + otpStr + '<br />' );
this.ref.detectChanges();
});
this.logStream.on('end', () => {
this.logOutput = this.sanitizer.bypassSecurityTrustHtml( this.logOutput + '<br />' );
this.ref.detectChanges();
});
'. Don't do that. Generate a HTML string, by concatenating strings together, then call bypassSecurityTrustHtml on that string. – JB Nizet Jan 27 '18 at 09:25