I have an article class as defined like so:
export class Article {
id : number;
isanon : boolean;
title: string;
link: string;
text: string;
subverse : string;
userID : string;
votes: number;
constructor(title: string, link: string, subverse : string, text : string, userID : string, votes?: number) {
this.title = title;
this.link = link;
this.text = text;
this.subverse = subverse;
this.userID = userID;
this.votes = votes || 0;
}
log() : void{
console.log("Title: " + this.title + " Link: " + this.link + " subverse: " + this.subverse);
}
domain(): string {
try {
const link: string = this.link.split('//')[1];
return link.split('/')[0];
} catch (err) {
return null;
}
}
voteUp(): void {
this.votes += 1;
}
voteDown(): void {
this.votes -= 1;
}
}
and I get the articles from the database using an observable service
export class HomeComponent implements OnInit {
articles : Article[];
and...
this.service.GetArticles(this.subverseStr).subscribe( (data)=>{
this.articles = <Article[]>data;
});
However, in my HTML template it doesn't recognize the domain() or any other TS functions.
<div class="meta">({{ article.domain() }})</div>
When the page is loaded, I get error:
core.umd.js:2837 EXCEPTION: Error in app/article/article.component.html:15:20 caused by: self.context.article.domain is not a function
It does recognize it as a function if I hard code my articles[] and it does recognize variable members. Any idea what is going on? Thanks.
GetArticles
and other relevant pieces. It isn't obvious at all thatdata
is an array ofArticle
instances, and it isn't obvious that{{ article...
refers toArticle
instance. MCVE is necessary. – estus 2 days ago