1
I have a child component staying at the father’s, as follows:
Parent component:
@Component({
selector: 'app-componente-pai',
template: `
<p id="elemento">componente pai</p>
<app-componente-filho></app-componente-filho>
`
})
export class Pai{
quantVezesAlterado: number = 0;
alterandoParagrafo(){
let elem = document.getElementById('elemento');
elem.innerHtml = 'componente pai alterado ' + this.quantVezesAlterado + ' vezes';
}
}
Child component:
@Component({
selector: 'app-componente-filho',
template: `
<a>chamar função do pai</a>
<div>
<!-- outros elementos -->
</div>
`
})
export class filho{ }
And I want to call the job alterandoParagrafo()
, existing in the parent component, where the anchor <a>
is clicked (and only the anchor, without affecting other components). How can I do this?
I’m using Angular 8.2.5
I don’t understand what the difficulty is, it’s not just putting an event to click the tag
app-componente-filho
?– LeAndrade