1

Component inheritance is quite straight forward in Angular >2, just a matter of extending the parent class:

import { ParentComponent } from './parent.component';

@Component({
  selector: 'child',
  templateUrl: './child.component.html'
})
export class ChildComponent extends ParentComponent {
}

This works pretty well for a lot of use cases.

Now, let's imagine that I have a parent class Person, and two children classes, Employee and Contractor. I don't know if a person is a contractor or an employee until I query the database.

So my question is, what is the best way to subclass Person based on a flag that is received at running time? Is there a design pattern that fits this use case?

1
  • 1
    The interfaces are lost as soon as the Typescript is compiled down anyway. Commented Jul 27, 2018 at 19:09

1 Answer 1

3

I think my issue can be resolved with dynamic component loading.

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

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.