2016-12-01 54 views
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) 
     ); 
    } 
} 

我已經搜索了這個問題,並找到了一些答案,但他們沒有幫助我理解它。

angular2: Supplied parameters do not match any signature of call target, even though i have all the needed params

chart.js - Supplied parameters do not match any signature of call target (angular2)

+0

.. ){...} .bind()'你可以使用'(..)=> {...}' –

回答

0

我發現我自己的錯誤,我必須使用最新版本rxjs,這裏的包JSON:不要使用`funtion(的

"dependencies": { 
    "@angular/common": "^2.2.4", 
    "@angular/compiler": "^2.1.2", 
    "@angular/core": "^2.2.4", 
    "@angular/http": "^2.1.4", 
    "@angular/platform-browser": "^2.1.2", 
    "@angular/platform-browser-dynamic": "^2.1.2", 
    "@angular/router": "^3.1.4", 
    "core-js": "^2.4.1", 
    "reflect-metadata": "^0.1.8", 
    "rxjs": "5.0.0-beta.12", 
    "systemjs": "^0.19.40", 
    "zone.js": "^0.6.26" 
    } 
相關問題