将角度服务传递给类和基类
发布时间:2020-12-17 17:05:12 所属栏目:安全 来源:网络整理
导读:我有以下课程: export class CellLayer extends BaseLayer { constructor(name: string,type: LayerType,private mapService: MapService) { super(name,type,mapService); }} 和相应的抽象类: export abstract class BaseLayer implements ILayer { priva
我有以下课程:
export class CellLayer extends BaseLayer { constructor(name: string,type: LayerType,private mapService: MapService) { super(name,type,mapService); } } 和相应的抽象类: export abstract class BaseLayer implements ILayer { private _name: string; private _type: LayerType; constructor(name: string,private mapService: MapService) { this._name = name; this._type = type; } } 应将全局MapService对象传递给这两个类. 但是,我现在收到以下错误:
解决方法
保护它.
Private表示属性对当前类是私有的,因此子组件不能覆盖它,也不能定义它. export abstract class BaseLayer implements ILayer { private _name: string; private _type: LayerType; constructor(name: string,protected mapService: MapService) { this._name = name; this._type = type; } } export class CellLayer extends BaseLayer { constructor(name: string,protected mapService: MapService) { super(name,mapService); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |