도메인의 루트에서 사용할 수 있어야합니다. 여기
가 (이 또한 라이센스를 추출)
ng build --prod
를 실행 한 후 내
dist
폴더의 스크린 샷이다 : 당신은이 코드를 수행하여 액세스 할 수 있어야합니다
! 은 (아차 나는 잊었다
을 : 당신은 또한
@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>
. https://gyazo.com/d4c4812dc1b9f5624ac0afb8775adb34 –
@BuffetTime 죄송합니다! 'HttpClient'는'@ angular/common/http'에서 가져와야한다는 점을 잊어 버렸습니다. 나는 또한 오래된'Http' 예제를 추가했다. – Edric
새로운 구현에서 오류가 발생했습니다. https://gyazo.com//096d7227c5e75fafe62ebdaf58287036 '{responseType : {new (data ?: string) : text; 프로토 타입 : 텍스트; }; } '형식의 매개 변수에 할당 할 수 없습니다.'{headers ?: HttpHeaders; 관찰 : "몸"; params ?: HttpParams; reportProgress ?: 부울; respons ... '. 'responseType'속성 유형이 호환되지 않습니다. '{new (data ?: string) : Text; 프로토 타입 : 텍스트; } '을 (를)'json '유형에 지정할 수 없습니다. (속성) 응답 유형 : { new (data ?: string) : 텍스트; 프로토 타입 : 텍스트; } –