【发布时间】:2017-07-07 22:05:16
【问题描述】:
我创建了 Angular2 + Typescript 项目。我有很多表,所以我想要一些类似基本组件的东西。
这是我的基础组件:
export abstract class ManagementComponent<T> implements BaseComponent {
protected selectedItem: T;
protected items: Array<T>;
}
现在有我的子组件。我想从 http 获取所有项目,然后将其分配到基类中
export class CompetencesComponent extends ManagementComponent<Competence> implements OnInit {
thisField: string;
constructor(private service: CompetencesService) {
super();
}
ngOnInit(): void {
this.getCompetences();
}
private getCompetences() {
this.service.getCompetences().subscribe(function (competences: Array<Competence>) {
this.thisField // ok
this.items // not ok
})
}
}
知道如何从订阅方法访问基本字段吗?
【问题讨论】:
标签: javascript angular typescript