Skip to content

Commit

Permalink
feat(core): add safeHtml opt to bypass sanitizing template HTML… (#2090)
Browse files Browse the repository at this point in the history
fix #2039
  • Loading branch information
aitboudad committed Mar 17, 2020
1 parent a96cae6 commit bbd7009
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/core/src/lib/templates/field-template.type.ts
@@ -1,8 +1,27 @@
import { Component } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { FieldType } from './field.type';

@Component({
selector: 'formly-template',
template: `<div [innerHtml]="field.template"></div>`,
template: `<div [innerHtml]="template"></div>`,
})
export class FormlyTemplateType extends FieldType {}
export class FormlyTemplateType extends FieldType {
get template() {
if (this.field && (this.field.template !== this.innerHtml.template)) {
this.innerHtml = {
template: this.field.template,
content: this.to.safeHtml
? this.sanitizer.bypassSecurityTrustHtml(this.field.template)
: this.field.template,
};
}

return this.innerHtml.content;
}

private innerHtml = { content: null, template: null };
constructor(private sanitizer: DomSanitizer) {
super();
}
}

0 comments on commit bbd7009

Please sign in to comment.