Directive | How | Source | Rendered |
ng-bind-html | Automatically uses $sanitize | <div ng-bind-html="snippet"> |
|
ng-bind-html | Bypass $sanitize by explicitly trusting the dangerous value | <div ng-bind-html="deliberatelyTrustDangerousSnippet()"> |
|
ng-bind | Automatically escapes | <div ng-bind="snippet"> |
an html\nclick here\nsnippet
'); }); it('should inline raw snippet if bound to a trusted value', function() { expect(using('#bind-html-with-trust').element("div").html()). toBe("an html\n" + "click here\n" + "snippet
"); }); it('should escape snippet without any filter', function() { expect(using('#bind-default').element('div').html()). toBe("<p style=\"color:blue\">an html\n" + "<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" + "snippet</p>"); }); it('should update', function() { input('snippet').enter('new text'); expect(using('#bind-html-with-sanitize').element('div').html()).toBe('new text'); expect(using('#bind-html-with-trust').element('div').html()).toBe('new text'); expect(using('#bind-default').element('div').html()).toBe("new <b onclick=\"alert(1)\">text</b>"); });Filter | Source | Rendered |
linky filter |
<div ng-bind-html="snippet | linky"> |
|
linky target |
<div ng-bind-html="snippetWithTarget | linky:'_blank'"> |
|
no filter | <div ng-bind="snippet"> |