错误TypeError:_co.function不是函数

Iva*_*ich 2 angular

这是我在尝试使子代调用父代的方法时遇到的错误:

在此处输入图片说明

孩子是最喜欢的组件。该方法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!");
  }

}
Run Code Online (Sandbox Code Playgroud)

app.component.html

<favorite   
       [is-favorite] = "post.isFavorite"  
       (change)  = "onFavoriteChange()"  
></favorite>
Run Code Online (Sandbox Code Playgroud)

最喜欢的组件

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() {
  } 
}
Run Code Online (Sandbox Code Playgroud)

Kam*_*ski 5

在app.component.html中进行更改

(change)  = "onFavoriteChange()"
Run Code Online (Sandbox Code Playgroud)

到(首字母大写)

(change)  = "OnFavoriteChange()"
Run Code Online (Sandbox Code Playgroud)

  • 是的!这就是问题所在。只要系统允许,我将检查您的答案是否解决了我的问题。 (2认同)