Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR TypeError: _co.function is not a function

Tags:

angular

This is the error I get when trying to make the child call a method of the parent:

enter image description here

The child is favorite component. The method onFavoriteChange() exists in the parent, but it's not triggered.

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  title = 'Ivans-world';
  post = {
    title:"Titulo",
    isFavorite: true
  }

  OnFavoriteChange(){  
    console.log("App Component. Triggered OnChanges(). Yupi!");
  }

}

app.component.html

<favorite   
       [is-favorite] = "post.isFavorite"  
       (change)  = "onFavoriteChange()"  
></favorite>

favorite.component.ts

import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { empty } from 'rxjs';

@Component({
  selector: 'favorite',
  templateUrl: './favorite.component.html',
  styleUrls: ['./favorite.component.css'],
})
export class FavoriteComponent implements OnInit {

  @Input('is-favorite') isFavorite: boolean;
  @Output() change = new EventEmitter();

  OnClick(){
    this.isFavorite = !(this.isFavorite);
    this.change.emit(); 
  } 

  ngOnInit() {
  } 
}
like image 226
Ivan Derlich Avatar asked Jan 16 '19 23:01

Ivan Derlich


1 Answers

In app.component.html change

(change)  = "onFavoriteChange()"

to (first capital letter)

(change)  = "OnFavoriteChange()"
like image 144
Kamil Kiełczewski Avatar answered Nov 19 '22 10:11

Kamil Kiełczewski