Angular 2 - 从基类继承提供者

时间:2017-03-07 16:36:55

标签: angular

我有以下BaseComponent。

@Component({
    providers: [PresetService, CollectionService, RecordService]
})
export class BaseComponent{
    constructor(private collectionService:CollectionService, private recordService:RecordService, private presetService:PresetService){
    }
}

现在所有的孩子都应该继承提供者及其实例:

我有以下BaseComponent。

@Component({ 
})
export class ChildComponent extends BaseComponent{
    constructor(){
        super()
    }
}

这似乎不可能,因为我需要从孩子那里打电话。所以我需要从子到基地传递给提供者实例。父母可以提供实例吗?

1 个答案:

答案 0 :(得分:1)

https://github.com/angular/angular/commit/f5c8e09

  

装饰者:

     

1)列出类的装饰器及其父类   祖先第一顺序

     

2)仅使用各种最后一个装饰器(例如   @Component / ...)

     

构造函数参数:如果某个类继承自父类和   不声明构造函数,它继承父类   构造函数,以及该父类的参数元数据。

     

生命周期钩子:遵循普通的类继承模型,即   即使方法是,也将调用父类的生命周期钩子   没有在儿童班中被覆盖。

作为解决方法,您可以使用

web.config
class index:
    def POST(self):
        web.config.obj.update({'foo': 'bar'})
        ...

def main():
    web.config.obj = MyObject()

...
相关问题