[英]Can't access member of Child Services in Angular 2
I create 2 services 我创建2个服务
export class BaseService {
constructor() { }
}
And another service like 还有另一项服务,例如
export class ChildService extends BaseService {
constructor() {
super();
}
sayHello() {
alert("Hello");
}
}
And i used it in component like 我在像这样的组件中使用它
constructor(private child : ChildService) {
this.child.sayHello(); // It will throw error that sayHello not available.
}
Your service should be Injectable: 您的服务应该是可注射的:
@Injectable
export class BaseService {
...
And should be provided to module if it is still not: 如果仍不能提供,则应提供给模块:
@NgModule
...
providers: [BaseService]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.