Search code examples
ember.jsweb-component

Extend Ember component without changing template


I have an Ember application and want to extend a component to override some functionality, but don't want to change or duplicate the template.

However, if I just import and extend the component, nothing is rendered.

How can I make my extended component render using the template that I extended from?


Solution

  • Thanks to the question answered here How can I share a template between two components using Ember CLI? I was able to add a layoutName to the child component pointing to the parent template and solved my problem. My code finally looks like this:

    import Ember from 'ember';
    import ExtendFromComponent from './extend-from';
    
    export default ExtendFromComponent.extend({
      layoutName: 'components/extend-from'
    });