加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

将角度服务传递给类和基类

发布时间: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对象传递给这两个类.

但是,我现在收到以下错误:

Types have separate declarations of a private property ‘mapService’.
(6,14): Class ‘CellLayer’ incorrectly extends base class ‘BaseLayer’.

解决方法

保护它.

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);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读