Angular 4扩展并实现

前端之家收集整理的这篇文章主要介绍了Angular 4扩展并实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个类Hero需要扩展GoogleCharts类.我还需要实现OnInit来从params获取一些数据.

我怎样才能做到这一点?

像这样:
export class Hero extends GoogleCharts implements OnInit {...

如果GoogleCharts已经实现了OnInit,你应该调用super.ngOnInit();在你的ngOnInit方法中做其他事情之前.

像这样:

interface OnInit {
    ngOnInit: () => void;
}

class GoogleCharts implements OnInit{

    ngOnInit() {
        //does some stuff here
    }

}

class Hero extends GoogleCharts implements OnInit{

    ngOnInit() {
        super.ngOnInit();
        //do my stuff here
    }

}

猜你在找的Angularjs相关文章