wper
wper

Reputation: 352

Ionic2 Supplied parameters do not match any signature of call target

I am trying to figure out why I get the following error when running my ionic 2 project:

Supplied parameters do not match any signature of call target. (Line 16)

the code it points to is as follows:

card.servce.ts

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(...);
    }
}

Not sure why I get this error, are there parameters missing from: this.http.get(this.cardsUrl)?


error

Angular Core: 2.2.1

Upvotes: 1

Views: 404

Answers (1)

Amee Prajapati
Amee Prajapati

Reputation: 696

getCards() returns a full filled promise but as per return type defined it should returns only a promise:

Option 1:

getCards(){
    return this.http.get(this.cardsUrl)
        .toPromise()
        .then(response => response.json().cards as Card[])
        .catch(...);
    }

Option 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(...);
}

Upvotes: 1

Related Questions