2017-11-01 1 views
0

에 3rdpartylicenses을 표시하는 방법, 나는 --extract-licenses를 사용합니다.는 각도 4 - 나는 내 웹 사이트에 HTML에 표시되는 라이센스를 원하는 때문에 나는 <code>"build-prod": "ng build --prod --extract-licenses"</code><a href="https://danielturcich.com/" rel="nofollow noreferrer">website</a> 내 라이브에 사용하는 내 <code>package.json</code> 빌드 과정에서 HTML

.txt 파일을 HTML 형식으로 표시하려면 어떻게해야합니까?

답변

1

도메인의 루트에서 사용할 수 있어야합니다. 여기

가 (이 또한 라이센스를 추출) ng build --prod를 실행 한 후 내 dist 폴더의 스크린 샷이다 : 당신은이 코드를 수행하여 액세스 할 수 있어야합니다

Dist folder

! 은 (아차 나는 잊었다

을 : 당신은 또한 @angular/common/http를 설치하고 각도 사에서 최근에 도입 HttpClient와 새로운 HttpClient)

을 사용해야합니다 이전 Http 사용

import { HttpClient } from '@angular/common/http'; 
export class AboutComponent implements OnInit { 
    constructor(private http: HttpClient){} 
    license: string; 
    ngOnInit(){ 
     this.http.get('/3rdpartylicenses.txt', {responseType: 'text'}) 
      .subscribe(result => { 
       this.license = result; 
      }) 
    } 
} 

: 나는 당신의 구현을 복제하는 것을 시도하고 있지만 http.get을 유형 'HttpClient를'존재하지 않는 '수'가 '속성을 말하는

import { Http } from '@angular/http'; 
export class AboutComponent implements OnInit { 
    constructor(private http: Http){} 
    license: string; 
    ngOnInit(){ 
     this.http.get('/3rdpartylicenses.txt') 
      .map(res => res.text()) 
      .subscribe(result => { 
       this.license = result; 
      }) 
    } 
} 
<pre [innerText]="license"></pre> 
+0

. https://gyazo.com/d4c4812dc1b9f5624ac0afb8775adb34 –

+0

@BuffetTime 죄송합니다! 'HttpClient'는'@ angular/common/http'에서 가져와야한다는 점을 잊어 버렸습니다. 나는 또한 오래된'Http' 예제를 추가했다. – Edric

+0

새로운 구현에서 오류가 발생했습니다. https://gyazo.com//096d7227c5e75fafe62ebdaf58287036 '{responseType : {new (data ?: string) : text; 프로토 타입 : 텍스트; }; } '형식의 매개 변수에 할당 할 수 없습니다.'{headers ?: HttpHeaders; 관찰 : "몸"; params ?: HttpParams; reportProgress ?: 부울; respons ... '. 'responseType'속성 유형이 호환되지 않습니다. '{new (data ?: string) : Text; 프로토 타입 : 텍스트; } '을 (를)'json '유형에 지정할 수 없습니다. (속성) 응답 유형 : { new (data ?: string) : 텍스트; 프로토 타입 : 텍스트; } –

관련 문제