My class is like this:
export class Image {
static getUrl(x: Image) {
return CONFIG.host + x.url
}
constructor(private url: string, public alt: string) {}
}
My template is like:
<img [src]="Image.getUrl(image)" [alt]="image.alt" >
My component is like:
export class MyComponent {
image: Image;
Image = Image;
}
For the moment I have to pass the class itself Image manually to the component, in order by use Image.getUrl. What's a standard way to use a custom function or class method in a template?
If I use instance methods, then if I receive a Json that contains a property looks like Image, I have to do a proper type cast before calling the method, which is not very convenient if it is in a nested json.
get url() { }. That way you can just access it like a regular property.image.url