Reputation: 499
I get ERROR TypeError: _co.onClick is not a function error with angular 2.
<span
class="glyphicon"
[class.glyphicon-star]="isFavorite"
[class.glyphicon-star-empty]="!isFavorite"
(click)="onClick()">
</span>
When user click the star that it should be color or empty. then my component ts file is here
@Component({
selector: 'favorite',
templateUrl: './favorite.component.html',
styleUrls: ['./favorite.component.css']
})
Upvotes: 8
Views: 11445
Reputation: 41
I had the same problem even after declaring the function in my component.So I changed the function name and it worked.
Upvotes: 4
Reputation: 4360
You need to declare that onClick function in your component.
@Component({
selector: 'favorite',
templateUrl: './favorite.component.html',
styleUrls: ['./favorite.component.css']
})
export class FavoriteComponent {
constructor() { }
onClick() {
console.log("star clicked");
}
}
Upvotes: 5