Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
    
Please, provide the code for GetArticles and other relevant pieces. It isn't obvious at all that data is an array of Article instances, and it isn't obvious that {{ article... refers to Article instance. MCVE is necessary. – estus 2 days ago

Try without the (). Like that:

{{arcticle.domain}}

This is basically a pointer to your function and Angular2 will manage to call that function

share|improve this answer
    
it's just empty when I try it without parenthesis. Like blank string. – Clay Smith 2 days ago
    
It won't 'manage to call that function' this way. And it isn't a function, too, that's what error message says. – estus 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.