本文介绍了提供的参数与api调用angular4上的调用目标的任何签名都不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个API来对用户 Covalent UI ://github.com/Teradata/covalent-quickstart/tree/develop/src/app/users/services"rel =" nofollow noreferrer>服务.如GitHub上的示例所示,它需要将一些数据从端点发布到表中.

I am consuming an api to Covalent UI, on user service. Which needs to post some data from an endpoint to the table as illustrated on the example from the GitHub.

这是我对该服务所做的修改.

Here is the modification I have made to the 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,
};

JSON API数据

JSON api data

[
    {
        "_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....."
            }
        }
    }
]

不确定自己在做什么错,对于您对此修复程序的评论,我们将不胜感激.

Am not sure what am doing wrong, I will appreciate your comment for this fix.

我收到下面的错误消息.

I get the error bellow.

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

从这行代码

推荐答案

如评论中提到的@Philipp.

As @Philipp mentioned in the comments.

因此应定义您的工厂:

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

这篇关于提供的参数与api调用angular4上的调用目标的任何签名都不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:27