Warning: I'm very new to Angular so if below question indicates that my approach is completely off the rails, please let me know.
I have a model AltChar
. It has a source
property which relates to a Source
model. To save bandwidth, the backend does not resolve the entire Source
object with all its data for each AltChar
, but rather includes an id
field and it transmits a list of Source
s separately.
Conversely, when I update an AltChar
over the API, I needn't transmit the entire Source
field: the id
is enough and the backend will resolve it on its side.
Here comes some code:
import { Source } from './source';
export interface AltCharInterface {
id: number;
source: Source | number;
prep: any;
}
export class AltChar implements AltCharInterface {
constructor (
public id: number,
public source: Source,
) {}
static readonly EMPTY_MODEL = {
id: null,
source: Source.EMPTY_MODEL,
} as AltChar;
prep = () => {
return {
'id': this.id,
'source': this.source.id,
}
};
}
Then, in my TS file, I want to transmit this data to the REST API using:
altCharService.addAltChar(this.altChar.prep())
.subscribe(data => altChars.push(this.altChar));
But it tells me that prep()
is not a function.