티스토리 뷰
반응형
string안에html tag가있고그것을화면에tag를적용하고싶으면
[innerHTML] 속성을사용하면된다.
ex) <td[innerHtml]="content?.reply">
Angular가innerHTML 속성을 이용해 출력한 결과는 불완전하다.
왜냐하면 Angular가 이들 요소를 잠재적인 위험 요소로 판단해 새니티제이션을 적용했기 때문이다.
새티니제이션은데이터내의잠재된위험요소를제거하는기능이다.
! angular 에서 팝업 및 데이터가 수시로 바뀌는 innerHTMLdmf 사용하는 경우에
id 및 name에 대한 security에대한 경고가 콘솔에 나온다.
그럴경우 새티니제이션을 예외적으로 허용 해줘야하는데 그 메서드가 bypassSecurityTrustHtml(v)이다.
import { Pipe, PipeTransform } from "@angular/core";
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
@Pipe({
name: 'sanitizeHtml'
})
export class SanitizeHtmlPipe implements PipeTransform {
constructor(private _sanitizer:DomSanitizer) {
}
transform(v:string):SafeHtml {
return this._sanitizer.bypassSecurityTrustHtml(v);
}
}
파이프를만들어준후사용해야한다.
<td[innerHtml]="content?.reply | sanitizeHtml">
<!-- 2018년 8월 16일 추가 -->
sanitization의 사용 목적은 XSS(Cross-Site-Scripting) 공격을 예방하기 위함이다.
Angular에서는 Sanitization And Security Contexts의 다음과 같이 정의한다.
- HTML is used when interpreting a value as HTML, for example, when binding to
innerHtml
. - Style is used when binding CSS into the
style
property. - URL is used for URL properties, such as
<a href>
. - Resource URL is a URL that will be loaded and executed as code, for example, in
<script src>
.
그리고 Sanitization을 사용하기 위해 위에서와 같이 DomSanitizer를 불러와 사용하는데 다음과 같은 함메서드들이 있다.
bypassSecurityTrustHtml
bypassSecurityTrustScript
bypassSecurityTrustStyle
bypassSecurityTrustUrl
bypassSecurityTrustResourceUrl
좀 더 자세한 정보는 Angular에 있다.
반응형
'FrontEnd > Angular' 카테고리의 다른 글
Angular Router Guard + parameter (0) | 2018.07.13 |
---|---|
양방향 바인딩 한글 짤리는 문제 (0) | 2018.07.10 |
라우터 파라미터 (0) | 2018.07.04 |
라우터 새로고침 (0) | 2018.06.26 |
Angular select (0) | 2018.06.22 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Router
- 파이썬3
- Redux
- localStorage
- react
- JPA
- Python
- Angular
- data table component
- angular router
- React-router
- data component module
- jQuery
- MySQL
- JavaScript
- data component
- JSON
- 파이썬
- facebook login
- mobx
- Java
- data gird component
- python3
- CSS
- Spring
- Spring Boot
- data grid component
- https://www.tistory.com/auth/logout/
- 페이스북 로그인
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함