1

我在用户服务上使用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.

从这行代码 在此处输入图像描述

4

1 回答 1

0

正如评论中提到的@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)
}
于 2017-10-18T00:16:01.643 回答