2017-10-16 5 views
1

Je consomme une API à Covalent UI, sur l'utilisateur service. Ce qui doit publier des données d'un point de terminaison à la table comme illustré sur l'exemple du GitHub.Les paramètres fournis ne correspondent à aucune signature de l'appel cible sur l'appel api angulaire4

Voici la modification que j'ai apportée au service.

import { Provider, SkipSelf, Optional, InjectionToken } from '@angular/core'; 
import { Response, Http } from '@angular/http'; 
import { Observable } from 'rxjs/Observable'; 

import { HttpInterceptorService, RESTService } from '@covalent/http'; 
import { ApiService } from '../../../../services/api.service'; 
import { AuthService } from '../../../../services/auth.service'; 

export interface IUser { 
    _id: string; 
    email:string; 
    createdAt: Date; 
    profile: { 
     name: string; 
     gender: string; 
     location: String; 
     picture: { 
      // data: Buffer; 
      contentType: string; 
     } 
    } 
} 

export class UserService extends RESTService<IUser> { 

    constructor(private _http: HttpInterceptorService, api: string, 
       private authService: AuthService, 
       private api2: ApiService,) { 
    super(_http, { 
     baseUrl: api, 
     path: '/dashboard/users', 
    }); 
    } 

    staticQuery(): Observable<IUser[]> { 
    // return this._http.get('data/users.json') 
    // .map((res: Response) => { 
    // return res.json(); 
    // }); 
    return this.api2.get('auth/account/users') 
    .map((res: Response) => { 
     return res.json(); 
    }); 
} 
} 

export const USERS_API: InjectionToken<string> = new InjectionToken<string>('USERS_API'); 

export function USER_PROVIDER_FACTORY(
    parent: UserService, interceptorHttp: HttpInterceptorService, api: string): UserService { 
    return parent || new UserService(interceptorHttp, api);//<---- This is where I get the error mention. 
} 

export const USER_PROVIDER: Provider = { 
    // If there is already a service available, use that. Otherwise, provide a new one. 
    provide: UserService, 
    deps: [[new Optional(), new SkipSelf(), UserService], HttpInterceptorService, USERS_API], 
    useFactory: USER_PROVIDER_FACTORY, 
}; 

données JSON api

[ 
    { 
     "_id": "59d665c3acbde702b47d3987", 
     "updatedAt": "2017-10-07T17:23:00.498Z", 
     "createdAt": "2017-10-05T17:02:59.526Z", 
     "email": "[email protected]", 
     "password": "$2a$05$z1mRUWqqUfM8wKMU/y9/sOLssAKcV7ydxi0XJyTR1d3BI2X7SSsoy", 
     "tokens": [], 
     "role": "admin", 
     "__v": 0, 
     "profile": { 
      "name": "F.name L.name", 
      "gender": "Female", 
      "location": "my place", 
      "avatar": { 
       "contentType": "image/png", 
       "data": "iVBORw0KGgoAAAANSUhEUgAAAaYAAAFmCAYAAAAmm....." 
      } 
     } 
    } 
] 

Je ne suis pas sûr de ce que je fais mal, je vous remercie de votre commentaire à ce correctif.

Je reçois l'erreur ci-dessous.

users/services/user.service.ts (51,20): Supplied parameters do not match any signature of call target. 

A partir de cette ligne de code enter image description here

+0

Postez le erreur exacte et complète que vous obtenez, ainsi que le code correspondant. –

+0

J'ai mis à jour. –

+1

La classe 'UserService' attend 4 arguments dans le constructeur, mais vous n'en fournissez que 2 dans la fonction' USER_PROVIDER_FACTORY'. – Philipp

Répondre

0

Comme mentionné @Philipp dans les commentaires.

La classe UserService attend 4 arguments du constructeur, mais vous ne fournit 2 dans la fonction USER_PROVIDER_FACTORY.

Par conséquent, votre usine doit être définie:

export function USER_PROVIDER_FACTORY(
    parent: UserService, interceptorHttp: HttpInterceptorService, api: string, 
    authService: AuthService, api2: ApiService 
): UserService { 
    return parent || new UserService(interceptorHttp, api, authService, api2) 
}