沒有提供錯誤我想寫類,將範圍的HTTP和添加頁眉到每個請求,但是當我嘗試注入這個類供應商,我得到這個錯誤:在角2
browser_adapter.ts:73 EXCEPTION: Error: Uncaught (in promise): No provider for HttpClient! (ListPage -> DealProvider -> HttpClient)
代碼供應商:
import {Injectable} from 'angular2/core';
import {HttpClient} from './http-client';
import 'rxjs/add/operator/map';
/*
Generated class for the DealProvider provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class DealProvider {
static get parameters() {
return [[HttpClient]]
}
constructor(http) {
this.http = http;
this.data = null;
}
load() {
if (this.data) {
return Promise.resolve(this.data);
}
return new Promise(resolve => {
this.http.get('http://apiary-mock.com/deal/list/?page=1&search=ahoj&category=1&city=1')
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
}
}
代碼的HttpClient類
import {Injectable} from 'angular2/core';
import {Http, Headers} from 'angular2/http';
@Injectable()
export class HttpClient {
static get parameters() {
return [[Http], [Headers]]
}
constructor(http, headers) {
this.http = http;
}
createHeaders(headers) {
headers.append('AppVersion', '1.0.0');
headers.append('DeviceIdent', 'uuid');
headers.append('Session', 'sdawdbkj213345b345hj3b45');
}
get(url) {
let headers = new Headers();
this.createHeaders(headers);
return this.http.get(url, {
headers: headers
});
}
}
感謝您的幫助。
看起來像'[[Http,Headers]]'實際上應該是'[[Http],[Headers]]'我沒有辦法驗證它。 –