MEAN stack/Angular2

Angular2 :: 'unsafe value' exception

내가달이다 2017. 2. 1. 07:13

새로 프로젝트하면서 iframe 태그 src ="" 안에 ngfor 데이터를 넣어야될 상황이생겼다


1
 <iframe id="{{res.iframe}}" width="100%" height="100%" src="{{res.src}}"></iframe>
cs



실행을 해보니 


Error: unsafe value used in a resource URL context


이런 에러를 뱉어내는것이아닌가.. 이것때문에 삽질했습니다 뭐가 잘못된건지 .... 


다행히 구글링을해서 해결했습니다 



1
import {DomSanitizer} from "@angular/platform-browser";
cs

1
constructor(private domSanitizer : DomSanitizer)
cs

1
   this.pdfUrl = this.domSanitizer.bypassSecurityTrustResourceUrl(res.iframe);
cs


컴포넌트에 임포트 시켜줍시다



1
 <iframe id="{{res.iframe}}" width="100%" height="100%" [src]="this.pdfUrl">
cs


그후 위와 같이 변경후 실행해주니 정상적으로 URL 주소를 읽어옵니다