13

Is it possible to extend a component in Angular 2 and still use the inputs and outputs in the parent?

export class Book {
  @Input() name;
}

export class EBook extends Book {
  @Input() downloadUrl;
  @Input() size;
}

When I try to extend a component everything inside the class works except the code that need attributes/decorators, like inputs and outputs. I made a plunker that illustrates the problem: http://plnkr.co/edit/cfTKgScbaXMmEMoGY0zr

Book is a base component with one input/output Name.

EBook inherits from Book and adds input/output DownloadUrl, Size.

As you can see in the plunker, EBook doesn't get a name since the input is defined in Book and not in EBook

2 Answers 2

7

As for the current version of Angular (7.0.1 while writing this), your use case is perfectly supported. And the issue linked by Oliver has been closed.

Created an example Stackblitz (only highlighting input decorators): https://stackblitz.com/edit/angular-fepmtp

Sign up to request clarification or add additional context in comments.

Comments

5

as for rc4, input decorators are only inherited if the sub-class has no input decorators itself. otherwise you have to copy all the declarations.

its a known issue, you can follow up here: https://github.com/angular/angular/issues/5415

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.