使用Typesciprt通过继承公开Angular2中的公共函数

时间:2016-06-22 13:56:44

标签: inheritance typescript angular extends

假设我有一个扩展CommonComponent的HealthBar组件,我想访问baseComponent中的公共事件服务。

export class CommonComponent { 

constructor(private eventService:EventService){}

/*
broadcast (eventName, eventObj){
    let broadcastStr = this.name + " broadcast " + eventName;
    this.log(broadcastStr, eventObj)
    this.eventService.broadcast(eventName, eventObj );
}
*/

public broadcast = function(eventName, eventObj){
    this.eventService.broadcast(eventName, eventObj );
}

healthBar可以访问旧的" public broadcast = function"但不是新注释掉的broadcast()语法。我以为他们是一回事,不是吗?为什么广告()不公开给儿童组件?

0 个答案:

没有答案