When trying to extend the fabric Text object with additional parameters in Angular, I'm successful up to the part of serializing it (e.g. the new property 'fieldname' shows up in JSON). However the code fails when trying to read it back using this.canvas.loadFromJSON
ERROR TypeError: Cannot read properties of undefined (reading 'fromObject')
My code for the extended Object looks like this:
interface ITextFieldOptions extends fabric.TextOptions {
fieldname?: string;
}
export interface TextField extends ITextFieldOptions { }
export class TextField extends fabric.Text implements ITextFieldOptions {
public constructor(options: ITextFieldOptions) {
options.type = 'textField';
options.text = '{'+options.fieldname+'}';
super('initialize', options);
}
toObject(propertiesToInclude?: string[]): any {
propertiesToInclude = (propertiesToInclude || []).concat(
['fieldname']
);
return super.toObject(propertiesToInclude);
}
}
What am I missing to read my extended object back to the canvas?