私のライブwebsite"build-prod": "ng build --prod --extract-licenses"
のために私が使用するビルドプロセスでは、--extract-licenses
を使用します。私のウェブサイトでHTMLで表示されるライセンスを持っているからです。角度4 - HTMLでThirdpartylicensesを表示する方法
この.txt
ファイルをHTML形式で表示するにはどうすればよいですか?
私のライブwebsite"build-prod": "ng build --prod --extract-licenses"
のために私が使用するビルドプロセスでは、--extract-licenses
を使用します。私のウェブサイトでHTMLで表示されるライセンスを持っているからです。角度4 - HTMLでThirdpartylicensesを表示する方法
この.txt
ファイルをHTML形式で表示するにはどうすればよいですか?
ドメインのルートに存在する必要があります。
ここで(もライセンスを抽出する)ng build --prod
を実行した後に、私のdist
フォルダのスクリーンショットです:
あなたは、このコードに従うことによってそれにアクセスすることができるはずです: (おっと、私がいることを忘れてしまいました!あなたも@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>
。 https://gyazo.com/d4c4812dc1b9f5624ac0afb8775adb34 –
@BuffetTime申し訳ありません。 'HttpClient'は' @ angular/common/http'からインポートするべきであることを忘れてしまいました。また、古い 'Http'を使って例を追加しました。 – Edric
新しい実装からエラーが発生しました。 https://gyazo.com/096d7227c5e75fafe62ebdaf58287036 引数 '{responseType:{new(data ?: string):テキスト;プロトタイプ:テキスト; }; } 'は型のパラメータに割り当てられません' {headers ?: HttpHeaders; 「体」を観察する。 params ?: HttpParams; reportProgress?:ブール値。応答... '。 プロパティ 'responseType'の型は互換性がありません。 タイプ '{new(data ?: string):Text;プロトタイプ:テキスト; } 'はタイプ "" json "'に割り当てられません。 (プロパティ)responseType:{ new(data ?: string):テキスト; プロトタイプ:テキスト。 } –