Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error typeerror _co.onclick is not a function - Angular 2

Tags:

angular

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']
})
like image 293
user2552863 Avatar asked Jan 12 '18 06:01

user2552863


1 Answers

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");
      }
   }
like image 97
gyc Avatar answered Nov 15 '22 06:11

gyc