How do I get a variable from the parent, from a child component?
app.component
secret: string = '123'
child.component
@Input() secret;
console.log(this.secret);
=> undefined
Every example only shows template binding, for example [secret]="secret"
How do I just access the parent component's data from the child component?
Try it with property binding in the HTML of your parent (where you are using the child component) like so:
<child [secret]="secret"><child>
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