0
我試着明白爲什麼編譯器會拋出「提供的參數與調用目標的任何簽名不匹配」錯誤代碼中,在Angular 2.0中編譯在es6中。angular 2 http get瞭解「提供的參數與調用目標的任何簽名不匹配」
的誤差是在該行this.observer_data = this.http.get(this.get_all_buchungen_url ...
該服務提供的「BuchungsPos」類型巫的可觀察到的對象將與load_and_init_buchungen()
功能進行初始化。
服務:
@Injectable()
export class ReadBuchungenService {
public observer_data : Observable<BuchungPos>;
constructor (private http : Http) {}
public load_and_init_buchungen(timestamp : number) {
let params = new URLSearchParams();
params.set('timestamp', String(timestamp));
this.observer_data =
this.http.get(this.get_all_buchungen_url, { search: params })
.map(response => response.json());
return;
}
...
導入BuchngsPos類看起來像:
export class BuchungPos {
constructor(public id : number,
public date : string,
public name : boolean
) {}
}
在app.component
constructor(public readDataservice : ReadBuchungenService) {}
ngOnInit() {
this.readDataservice.load_and_init_buchungen(this.startTime);
}
,並使用在其他部件的對象:
export class TagComponent implements OnInit {
private buchungPos : BuchungPos;
constructor(private readBuchungenService : ReadBuchungenService) { }
ngOnInit() {
this.readBuchungenService.observer_data.subscribe(
function (data) {
this.buchungPos = data.data;
}.bind(this)
);
}
}
我已經搜索了這個問題,並找到了一些答案,但他們沒有幫助我理解它。
chart.js - Supplied parameters do not match any signature of call target (angular2)
.. ){...} .bind()'你可以使用'(..)=> {...}' –