我需要注入服务1成服务2像下面描述的:Angular2:如何注入一个服务到另一个服务
@Injectable()
export class myFirstService {
method1() {}
}
@Injectable()
export class mySecondService {
constructor(private service1: myFirstService) {}
method2(){
this.service1.method1();
}
}
但与此邮件时发生错误:
无法读取属性“ method1'undefined
请问有没有人在不改变main.ts或bootstrap方法的情况下解决这个问题?
非常感谢
您在哪里以及如何提供服务? –
你有一个错字'private service1 myFirstService'应该是=>'private service1:myFirstService'你没有':' – echonax
是的,私人服务1:myFirstService – da45