Skip to content

Instantly share code, notes, and snippets.

@Burgov
Last active August 7, 2022 19:07
Show Gist options
  • Save Burgov/709f59767f374313b07b17ac8627c04c to your computer and use it in GitHub Desktop.
Save Burgov/709f59767f374313b07b17ac8627c04c to your computer and use it in GitHub Desktop.
@Component({
selector: 'parent-component',
template: '<child-component><content-component></content-component></child-component>'
})
export class ParentComponent implements AfterViewInit {
}
@Component({
selector: 'child-component',
template: '<button (click)="this.increaseContentCounter()"></button><ng-content></ng-content>'
})
export class ChildComponent {
@ContentChild(ContentComponent) contentComponent: ContentComponent;
increaseContentCounter() {
this.contentComponent.increase();
}
}
@Component({
selector: 'content-component',
template: '<div>{{ counter }}</div>'
})
export class ContentComponent {
protected counter = 0;
increase() {
this.counter++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment