Last active
August 7, 2022 19:07
-
-
Save Burgov/709f59767f374313b07b17ac8627c04c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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