Angular2~HttpClientModule 配置


angular的資料很少,並且坑很多,報錯也不是很好解決,研究這個花了好幾天時間。

首先,先查看自己的anuglar版本是不是4.3.0以上,HttpClient是anuglar4.3中新加入的特性,在package.json中查看

復制代碼
  "@angular/animations": "^4.3.0",
  "@angular/common": "^4.3.0",
  "@angular/compiler": "^4.3.0",
  "@angular/core": "^4.3.0",
  "@angular/forms": "^4.3.0",
  "@angular/http": "^4.3.0",
  "@angular/platform-browser": "^4.3.0",
  "@angular/platform-browser-dynamic": "^4.3.0",
  "@angular/router": "^4.3.0",
復制代碼

 

1.在app.module.ts中導入

import { HttpClientModule } from '@angular/common/http';

並在imports加入:

imports: [
HttpClientModule
]

 

2.成員模塊中加入
import { HttpClientModule } from '@angular/common/http';
constructor(
private myhttp: HttpClient
) { }

 

就完了基本的配置。
 
轉自:http://www.cnblogs.com/cxd1008/p/7685789.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM