I would like to create extensions for some components already deployed in Angular 2, without having to rewrite them almost completely since the base component may undergo changes, and I would like these changes to be reflected in its derived components as well.
I created this simple example to try to better explain my questions:
With the following app/base-panel.component.ts base component:
import {Component, Input} from 'angular2/core'; @Component({ selector: 'base-panel', template: '<div class="panel" [style.background-color]="color" (click)="onClick($event)">{{content}}</div>', styles: [' .panel{ padding: 50px; } '] }) export class BasePanelComponent { @Input() content: string; color: string = "red"; onClick(event){ console.log("Click color: " + this.color); } }
Do you want to create another derived component by changing, for example, the basic behavior of the component in the case of the color example, app/my-panel.component.ts :
import {Component} from 'angular2/core'; import {BasePanelComponent} from './base-panel.component' @Component({ selector: 'my-panel', template: '<div class="panel" [style.background-color]="color" (click)="onClick($event)">{{content}}</div>', styles: [' .panel{ padding: 50px; } '] }) export class MyPanelComponent extends BasePanelComponent{ constructor() { super(); this.color = "blue"; } }
Full working example in Plunker
Note: obviously, this example is simple and can be solved, otherwise there is no need to use inheritance, but it is intended only to illustrate the real problem.
As you can see in the implementation of the derived component app/my-panel.component.ts , most of the implementation was repeated, and the only part that really was inherited was the BasePanelComponent class , but @Component had to be completely repeated, not just the changed parts as selector: 'my-panel' .
Is there a way to make literally complete inheritance of the Angular2 component by inheriting the definition of the marking / annotation class , such as @Component ?
Edit 1 - Feature Request
Angular2 request added to GitHub project : Extend / Inherit angular2 component annotations # 7968
Edit 2 - Closed request
The request was closed, for this reason , that for a short time it would not be known how to combine the decorator would be done. Leaving us without options. So my opinion is quoted in the issue .