is there any way to get the children from a subcomponent?
Imagine the following component tree:
I want to access Question Option
from App
to check all checkboxes.
See https://stackblitz.com/edit/angular-ghvsuu for an example.
You can do it in different way though.
Add @ViewChildren(QuestionOptionComponent) options
in QuestionComponent
instead of AppComponent
And in AppComponent
export class AppComponent {
@ViewChild(QuestionComponent) question
constructor(private elementRef: ElementRef) {}
checkAll() {
console.log("this.question", this.question) // found
console.log("this.options", this.question.options) // found
}
}
Forked DEMO
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