Http
을 사용하여 기존 앱을 HttpClient
으로 변경하려고하는데 오류가 있습니다. 각도 4 - HttpClient에 HTTP - 'someproperty'속성이 유형 객체에 존재하지 않습니다.
constructor(
// private http: Http
private http: HttpClient
) { }
getSidebar() {
// return this.http.get('http://localhost:3000/sidebar/edit-sidebar')
// .map(res => res.json());
return this.http.get('http://localhost:3000/sidebar/edit-sidebar');
}
그리고에 내 page.component.ts
나는 위의 라인 그러나이
this.sidebarService.getSidebar().subscribe(sidebar => {
this.sidebar = sidebar.content; // this does not work now
});
이 나는이 오류가 지금 나는이 코멘트를 얻는다 논평했다 :
Property 'content'
does not exist on type 'Object'.
그러나 만약 내가 console.log(sidebar)
다음과 같은 메시지가 표시됩니다.
{_id: "59dde326c7590a27a033fdec", content: "<h1>sidebar here</h1>"}
그래서 무엇이 문제입니까?
다시 한번, Http
은 작동하지만 HttpClient
은 그렇지 않습니다.
이 반환 this.http.get를 ('에 http : // localhost를 : 3000/사이드/편집 - 사이드 바') 시도 .MAP (고해상도 => 고해상도); –
여전히 동일하지만 어쨌든 httpclient를 사용하면 맵이 중복되는 것 같아요. –