我想将服务注入另一个服务.我注入标准角度服务(Http等)没有任何问题,但是当我尝试注入自己的服务时,我得到了一个例外.
例:
为MyService:
import {Injectable, Inject} from 'angular2/core';
import {AnotherService} from '../../services/another.service';
@Injectable()
export class MyService {
constructor(Inject(AnotherService) private anotherService: AnotherService) {
console.log(this.anotherService.get());
}
}
Run Code Online (Sandbox Code Playgroud)
AnotherService:
import {Injectable} from 'angular2/core';
@Injectable()
export class AnotherService {
constructor() { }
get() { return 'hello'); }
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用MyService时,我得到了 EXCEPTION: No provider for AnotherService!
我尝试过使用constructor(private anotherService: AnotherService),仍然会抛出异常.
谢谢!