I recently started trying out Aurelia (I'm new to Javascript and used to typed languages so I'm working from the typescript skeleton), and I ran into some odd issues with view inheritance that I don't understand.
I wanted to create two views with common functionality, which is why I wanted to create a common super class that both views could extend. This however caused unexpected behavior: when including both views in app.html, only one of the two shows, depending on the order of require statements.
I included a small minimal example below:
parent-view.ts
import {bindable} from 'aurelia-framework';
export abstract class ParentView {
@bindable title: string;
}
child-a-view.html
<template><div>${title} A</div></template>
child-a-view.ts
import {ParentView} from './parent-view'
export class ChildAView extends ParentView {
constructor() {
super()
}
}
child-b-view.html
<template><div>${title} B</div></template>
child-b-view.ts
import {ParentView} from './parent-view'
export class ChildBView extends ParentView {
constructor() {
super()
}
}
app.ts
export class App {}
app.html
<template>
<require from="./child-a-view"></require>
<child-a-view title="TitleA"></child-a-view>
<require from="./child-b-view"></require>
<child-b-view title="TitleB"></child-b-view>
</template>
This gives as output a page containing the text "TitleA B", while I'd expect two lines "TitleA A" and "TitleB B".
An alternative ordering of require statements in app.html
<template>
<require from="./child-b-view"></require>
<require from="./child-a-view"></require>
<child-a-view title="TitleA"></child-a-view>
<child-b-view title="TitleB"></child-b-view>
</template>
gives as output a page containing the text "TitleB A", while again I'd expect two lines "TitleA A" and "TitleB B".
Is this a bug in Aurelia, is it not allowed to inherit view classes, or am I doing something wrong here that causes this?