Last active
May 31, 2018 18:46
-
-
Save montyr75/71085efbb57117ca1b94d45286515d09 to your computer and use it in GitHub Desktop.
Angular 2 directive to safely inject HTML.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:html' show Element, NodeTreeSanitizer; | |
import 'package:angular2/core.dart' | |
show Directive, Input, OnChanges, SimpleChange; | |
@Directive(selector: '[safeInnerHtml]') | |
class SafeInnerHtml implements OnChanges { | |
Element _el; | |
SafeInnerHtml(this._el); | |
@Input() | |
String safeInnerHtml; | |
@override | |
void ngOnChanges(Map<String, SimpleChange> changes) { | |
_el.setInnerHtml(this.safeInnerHtml, treeSanitizer: NodeTreeSanitizer.trusted); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span [safeInnerHtml]="someHtml"></span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment