Reputation: 71
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;
}
}
Upvotes: 1
Views: 697
Reputation: 6802
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;
}
}
Upvotes: 3