Featherjs和Angular 2错误

时间:2017-09-08 15:48:17

标签: angular2-services feathersjs

我试图将FeathersJS与Angular 2一起使用,但我无法让它工作,我遵循这里的指南:Angular2 Guide with Feathers 我的问题是我按照这样的说法创建服务:

import * as feathers from 'feathers/client';
import * as hooks from 'feathers-hooks';
import * as rest from 'feathers-rest/client';
import { Injectable } from '@angular/core';
const superagent = require('superagent');

const HOST = 'https://myurl.com/';

@Injectable()
export class RestService {
  private _app: any;
  constructor() {
    this._app = feathers() // Initialize feathers
      .configure(rest(HOST).superagent(superagent)) // Fire up rest
      .configure(hooks()); // Configure feathers-hooks
  }
}

我试着像这样使用它

import { RestService } from './rest.service';
import { Injectable } from '@angular/core';

@Injectable()
export class UsersService {

  private _rest;

  constructor( private _restService: RestService ) {
    this._rest = _restService.getService('users');
  }

}

我得到错误:“''服务''在'RestService'类型

上不存在

我认为我必须实例化该服务,但我可以做到这一点,非常感谢任何帮助。

此致

1 个答案:

答案 0 :(得分:0)

我使用上一版本3.0.1,并使用这些命令安装:

npm install @feathersjs/feathers @feathersjs/socketio-client --save
npm install @feathersjs/authentication-client --save
npm install socket.io-client --save

在Angular 4中,我的服务是:

import { Injectable } from '@angular/core';

import feathers from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio-client';
import authencl from '@feathersjs/authentication-client';

import io from 'socket.io-client';

@Injectable()
export class AppService {

  private urlServer = 'http://localhost:3030';
  private socket = io(this.urlServer, {
    transports: ['websocket'],
    forceNew: true
  });

  app: any;

  constructor() {
    this.app = feathers()
        .configure(socketio(this.socket))
        .configure(authencl());
  }
}