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(RES => RES); –
まだ同じですが、とにかく私はhttpclientを使うと地図が冗長だと思います。 –