When the ancestor Scope
does not define attached
or detached
methods, the hook methods attached
and detached
in the view-model below are not invoked.
import { Item } from '../item';
import { Scope } from '../scope/scope';
export class RepeatingSection extends Scope {
public TemplateModel: any;
private UpdateTimerHandle: number;
public activate(activationParameter: any) {
super.activate(activationParameter);
this.TemplateModel = JSON.parse(`{"Type": "scope", "Children": ${this.Model.Template}}`);
}
public attached() {
console.log("attached");
}
public detached() {
console.log("detached");
}
public add(): void {
// update the model and binding adds the item (which is a view-model)
let raw = `{ "Type": "scope", "Children": ${this.Model.Template} }`;
let row = JSON.parse(raw);
this.Model.Children.push(row);
}
public remove(item: Item): void {
// update the model, and binding removes the item (which is a view-model)
this.Model.Children.splice(this.Model.Children.indexOf(item.Model), 1);
}
}
Adding stub methods to Scope
causes Aurelia to find the methods on RepeatingSection
public attached(): void {
//this exists because without it Aurelia can't find attached on RepeatingSection
}
public detached(): void {
//this exists because without it Aurelia can't find attached on RepeatingSection
}