简体   繁体   English

Angular2从另一个服务调用服务

[英]Angular2 calling a service from another service

I have 2 services - 1/Files and 2/FTPClient in angular2. 我有2个服务-angular2中的1 / Files和2 / FTPClient。

They are Singleton services - and work perfectly when injected into a component through its constructor like this : 它们是Singleton服务-当通过其构造函数注入到组件中时可以完美地工作,如下所示:

constructor(public filesIn:Files, public ftpIn:FTPClient){}

SO now I would like to use the Files server within the FTPClient itself...so I try the same thing. 所以现在我想在FTPClient本身中使用文件服务器...所以我尝试同样的事情。 This is my code for the constructor of the FTPClient service: 这是我的FTPClient服务的构造函数代码:

constructor(public filesIn:Files) {
        this.files = filesIn;
    }

But this throws the error: 但这会引发错误:

Can't resolve all parameters for FTPClient (?)

My application only has one module - and both the Files and FTPClient are in the providers list : 我的应用程序只有一个模块-文件和FTPClient都在提供程序列表中:

 providers: [APIData,FTPClient,Files,SSHClient, WINDOW_PROVIDER]

Please can you shed some light on what I am doing wrong here! 请您能告诉我我在这里做错了什么!

我必须在类开始的上方添加@Injectable()装饰器-并通过添加以下@Injectable() Injectable导入文件:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM