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

前端之家收集整理的这篇文章主要介绍了将角度服务传递给类和基类前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下课程:

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

猜你在找的Angularjs相关文章