Angular - Component different templates

Michalis picture Michalis · May 26, 2017 · Viewed 13.8k times · Source

I have a component "course". I use this component to a list. This list sometimes is horizontal and some times is vertical. Can I choose dynamicaly inside the component the template file?

@Component({
    selector: 'course',
    templateUrl: getTemplateFile()
})

Something like that would be great feature!

Answer

Michalis picture Michalis · Jun 28, 2017

I think that this tutorial is very helpful

https://scotch.io/tutorials/component-inheritance-in-angular-2

You can simply extend your base component and overwrite the template. This allows you to have different components with the exact same functionality, but different templates.