1

I'm trying to get isActivated from an @Input() tweets. But When I want to store the isActivated to a variable this error comes up: Tweet is not defined. and Here's my code:( And sorry for my English too)

export class SingleTweetComponent { 
    @Input() tweet;
    isActivated = tweet.isActivated;
    likeButton($event){
        this.tweet.totalLikes = this.tweet.totalLikes - 1;
    }
}

1 Answer 1

3

Because tweet is not defined when you're trying to use it. At the time of computing properties you don't have input data yet.

To fix that you can take it in OnInit hook of the component:

export class SingleTweetComponent { 
    @Input() tweet;

    ngOnInit() {
      this.isActivated = this.tweet.isActivated;
    }

    likeButton($event) {
      this.tweet.totalLikes = this.tweet.totalLikes - 1;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.