Angularjs Ionic2提供的参数与调用目标的任何签名都不匹配
我正在试图找出运行ionic 2项目时出现以下错误的原因: 提供的参数与调用目标的任何签名都不匹配。(第16行) 它所指的代码如下: 卡服务tsAngularjs Ionic2提供的参数与调用目标的任何签名都不匹配,angularjs,angular,typescript,ionic2,angular-http,Angularjs,Angular,Typescript,Ionic2,Angular Http,我正在试图找出运行ionic 2项目时出现以下错误的原因: 提供的参数与调用目标的任何签名都不匹配。(第16行) 它所指的代码如下: 卡服务ts import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/toPromise'; import { Card } from "./cards"; @Injectable()
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import { Card } from "./cards";
@Injectable()
export class CardService {
private cardsUrl = 'my_url_here';
constructor(private http: Http) {}
getCards(): Promise<Card[]> {
return this.http.get(this.cardsUrl) // Error is here
.toPromise()
.then(response => response.json().cards as Card[])
.catch(...);
}
}
从'@angular/core'导入{Injectable};
从'@angular/Http'导入{Http};
导入“rxjs/add/operator/toPromise”;
从“/cards”导入{Card};
@可注射()
出口级信用卡服务{
private cardsUrl='my_url_here';
构造函数(私有http:http){}
getCards():承诺{
返回this.http.get(this.cardsUrl)//此处有错误
.toPromise()
.then(response=>response.json().cards as Card[])
.捕获(…);
}
}
不确定为什么会出现此错误,是否缺少以下参数:
this.http.get(this.cardsUrl)
Angular Core:2.2.1getCards()返回一个完整的承诺,但根据定义的返回类型,它应该只返回一个承诺: 备选案文1:
getCards(){
return this.http.get(this.cardsUrl)
.toPromise()
.then(response => response.json().cards as Card[])
.catch(...);
}
备选案文2:
getCards(): Promise<Card[]> {
return this.http.get(this.cardsUrl)
.toPromise();
}
// use this function returnResult()
returnResult(){
this.getCards().then(response => response.json().cards as Card[])
.catch(...);
}
getCards():承诺{
返回this.http.get(this.cardsUrl)
.toPromise();
}
//使用此函数returnResult()
returnResult(){
this.getCards().then(response=>response.json().cards as Card[])
.捕获(…);
}
tryprivate cardsUrl:string='my_url_here'
@suraj相同的问题。谢谢,这个特定的实现仍然会产生相同的错误,但我会将其标记为正确的,因为您的解释确实帮助我解决了这个问题。很高兴提供帮助:)