This is the error I get when trying to make the child call a method of the parent:
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() {
}
}
In app.component.html change
(change) = "onFavoriteChange()"
to (first capital letter)
(change) = "OnFavoriteChange()"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With