How to extend / inherit components?

后端 未结 12 831
萌比男神i
萌比男神i 2020-12-02 04:11

I would like to create extensions for some components already deployed in Angular 2, without having to rewrite them almost completely, as the base component could undergo ch

12条回答
  •  猫巷女王i
    2020-12-02 04:58

    You can inherit @Input, @Output, @ViewChild, etc. Look at the sample:

    @Component({
        template: ''
    })
    export class BaseComponent {
        @Input() someInput: any = 'something';
    
        @Output() someOutput: EventEmitter = new EventEmitter();
    
    }
    
    @Component({
        selector: 'app-derived',
        template: '
    {{someInput}}
    ', providers: [ { provide: BaseComponent, useExisting: DerivedComponent } ] }) export class DerivedComponent { }

提交回复
热议问题