2017-11-01 20 views
0

私のライブwebsite"build-prod": "ng build --prod --extract-licenses"のために私が使用するビルドプロセスでは、--extract-licensesを使用します。私のウェブサイトでHTMLで表示されるライセンスを持っているからです。角度4 - HTMLでThirdpartylicensesを表示する方法

この.txtファイルをHTML形式で表示するにはどうすればよいですか?

答えて

1

ドメインのルートに存在する必要があります。

ここで(もライセンスを抽出する)ng build --prodを実行した後に、私のdistフォルダのスクリーンショットです:

Dist folder

あなたは、このコードに従うことによってそれにアクセスすることができるはずです: (おっと、私がいることを忘れてしまいました!あなたも@angular/common/httpをインストールし、角度4で最近導入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):テキスト;プロトタイプ:テキスト; }; } 'は型のパラメータに割り当てられません' {headers ?: HttpHeaders; 「体」を観察する。 params ?: HttpParams; reportProgress?:ブール値。応答... '。 プロパティ 'responseType'の型は互換性がありません。 タイプ '{new(data ?: string):Text;プロトタイプ:テキスト; } 'はタイプ "" json "'に割り当てられません。 (プロパティ)responseType:{ new(data ?: string):テキスト; プロトタイプ:テキスト。 } –

関連する問題