Jay Bienvenu
Jay Bienvenu

Reputation: 3299

Aurelia: Deriving a component from another and reusing HTML

In Aurelia, how do I derive a component from another component reusing the HTML view from the source component?

I have a component BarGraph that renders simple bar graphs. This component has files bar-graph.js and bar-graph.html. I want to derive a set of components from BarGraph. Each *BarGraph class will have custom logic, but all of the derived components will have the same HTML as the original component. I want to store the HTML for the components in one file and reuse it in each *BarGraph class.

Upvotes: 0

Views: 455

Answers (1)

qtuan
qtuan

Reputation: 687

You can use @useView. For example:

import {useView} from 'aurelia-framework';

@useView('./bar-graph.html')
export class AnotherBarGraph {
  // Your logic here
}

Documentation here

EDIT: Extending custom element using inheritance is currently not supported. An important point is "Inheritance of Bindables doesn't work". See this issue.

Upvotes: 5

Related Questions