angular 2 http get了解“提供的参数与调用目标的任何签名不匹配”

angular 2 http get了解“提供的参数与调用目标的任何签名不匹配”

问题描述:

我试着明白为什么编译器会抛出“提供的参数与调用目标的任何签名不匹配”错误代码中,在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()'你可以使用'(..)=> {...}' –

我发现我自己的错误,我必须使用最新版本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" 
    }