InterviewHubPRO
Section Overview
Q170

Question 170 of 283

Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

60%
Angular & Signals (283 Qs)•Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

What is DOM sanitizer?

DomSanitizer is used to help preventing Cross Site Scripting Security bugs (XSS) by sanitizing values to be safe to use in the different DOM contexts.

Practical Code Example

typescript
// DomSanitizer: Explicitly trusts safe values when required:
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

export class SafeComponent {
  safeHtml: SafeHtml;
  constructor(private sanitizer: DomSanitizer) {
    this.safeHtml = this.sanitizer.bypassSecurityTrustHtml('<b>Trusted HTML</b>');
  }
}