remove tag when update html.
- it's possible head and body tag not remove when update html.
I need too keep the html, body and head tags.
Having the same issue, Is there any solution to this issue?
The same problem. Does anyone have a solution?
Thank you for reporting this issue. Let me explain what's happening with <html>, <head>, and <body> tags.
Root Cause
The Angular Editor uses DomSanitizer by default, which removes certain tags for security reasons. The <html>, <head>, and <body> tags are considered document-level elements and are typically stripped by sanitization.
Why This Happens
// When you paste or set HTML like:
<html>
<head><title>Document</title></head>
<body>
<p>Content</p>
</body>
</html>
// DomSanitizer removes document-level tags, leaving:
<p>Content</p>
This is intentional security behavior - these tags can conflict with the parent page's structure.
Solutions
Option 1: Disable Sanitization (Use with Caution!)
config: AngularEditorConfig = {
sanitize: false, // ⚠️ Only if you trust the HTML source!
// ... other config
};
⚠️ WARNING: Only disable sanitization if:
- You control all HTML content
- Content comes from trusted sources
- You implement your own XSS protection
Option 2: Use Custom Sanitizer
If you need <head> tags for specific reasons (email templates, etc.):
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
constructor(private sanitizer: DomSanitizer) {}
// Custom sanitization that preserves document tags
customSanitize(html: string): SafeHtml {
return this.sanitizer.sanitize(SecurityContext.HTML, html) || '';
}
Option 3: Store Document Parts Separately (Recommended)
Instead of storing full HTML documents in the editor:
// Store head and body separately
interface EmailTemplate {
head: string; // <title>, <style>, <meta> tags
body: string; // Actual content (edited in angular-editor)
}
// Combine when needed
buildFullDocument(template: EmailTemplate): string {
return `
<!DOCTYPE html>
<html>
<head>${template.head}</head>
<body>${template.body}</body>
</html>
`;
}
Use Cases
Email Templates
If you're building email templates, you don't need <html>/<body> tags in the editor:
<!-- Edit only the content in angular-editor -->
<angular-editor [(ngModel)]="emailBody" [config]="config"></angular-editor>
<!-- Wrap it when sending -->
<html>
<head>
<style>/* Your email styles */</style>
</head>
<body>
{{ emailBody }} <!-- Insert editor content here -->
</body>
</html>
Need Help?
Could you share your specific use case? Understanding why you need to preserve <html>, <head>, and <body> tags will help us provide a better solution.
Common scenarios:
- Email templates → Use Option 3 (separate storage)
- Full HTML documents → Consider a different editor (this is a content editor, not an HTML IDE)
- Specific head content → Extract and store separately
Please reply with your use case so we can provide a tailored solution!