ระดับกลาง
4 ตุลาคม 2569

หาบั๊กให้เจอ: Angular

โค้ดหนึ่งชิ้น หาบั๊กให้เจอ หรือพิสูจน์ว่าไม่มีบั๊ก

typescript
1import { Component } from '@angular/core';
2import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
3
4@Component({
5  selector: 'app-comment',
6  template: '<div [innerHTML]="safeComment"></div>'
7})
8export class CommentComponent {
9  safeComment: SafeHtml = '';
10  userComment = '';
11
12  constructor(private sanitizer: DomSanitizer) {}
13
14  displayComment(input: string) {
15    this.userComment = input;
16    this.safeComment = this.sanitizer.bypassSecurityTrustHtml(input);
17  }
18}

คลิกบรรทัดที่เป็นต้นเหตุของปัญหา

คำตัดสินของคุณ

วันละหนึ่งครั้ง คำตอบจะแสดงทันทีหลังจากนั้น

รักษาสถิติต่อเนื่องของคุณ

สร้างบัญชีเพื่อเก็บสถิติต่อเนื่องและติดตามความคืบหน้า

สร้างบัญชี