Okay the title may be a little confusing. My child component is in its own module and is using services that aren't available to the parent component.
I want to change some values in the child component on click of a button and was messing around and set something up like this.
@Component({
selector: 'app-parent-component'
template: `
<button (click)="refreshData()" />
<app-child-component> </app-child-component>
`
})
export class ParentComponent{
refreshData() {
ChildComponent.runRefresh()
}
}
@Component({
selector: 'app-child-component'
template: ``
})
export class ChildComponent{
static runRefresh() {
console.log('refreshing')
// Do things involving data on a service scoped to this component/module
}
}
I was curious if there was something inherently wrong with this approach? Are there better ways to solve the problem. Im familiar with checking for the changes in NgOnChanges event.
I guess what i'm trying to do is call a method inside of the child component, that uses the child component resources on a scoped service, from a parent component.
Edit: Also aware of using @ViewChild and not making the child components method static. Maybe that is the only "right" way?