错误TypeError:_co.function不是函数

时间:2019-01-16 23:12:51

标签: angular

这是我试图让孩子调用父母方法的错误:

enter image description here

孩子是最喜欢的组件。 父级中存在onFavoriteChange()方法,但未触发。

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() {
  } 
}

1 个答案:

答案 0 :(得分:2)

在app.component.html中更改

(change)  = "onFavoriteChange()"

收件人(大写字母)

(change)  = "OnFavoriteChange()"
相关问题