Search code examples
angularangular-components

Angular - Component different templates


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!


Solution

  • I think that this tutorial is very helpful

    https://www.digitalocean.com/community/tutorials/angular-component-inheritance

    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.