簡體   English   中英

提供的參數與api調用angular4上的調用目標的任何簽名都不匹配

[英]Supplied parameters do not match any signature of call target on api call angular4

我在用戶服務上使用了Covalent UI的api。 如GitHub上的示例所示,它需要將一些數據從端點發布到表中。

這是我對該服務所做的修改。

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,
};

JSON API數據

[
    {
        "_id": "59d665c3acbde702b47d3987",
        "updatedAt": "2017-10-07T17:23:00.498Z",
        "createdAt": "2017-10-05T17:02:59.526Z",
        "email": "me@mail.com",
        "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....."
            }
        }
    }
]

不確定發生了什么問題,對於您對此修復程序的評論,我們將不勝感激。

我收到錯誤提示。

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

從這行代碼 在此處輸入圖片說明

正如@Philipp在評論中提到的。

UserService類在構造函數中需要4個參數,但在USER_PROVIDER_FACTORY函數中僅提供2個參數。

因此,應定義您的工廠:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM