Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular access parent variable from child component

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?

like image 283
bruh Avatar asked Aug 07 '26 21:08

bruh


1 Answers

Try it with property binding in the HTML of your parent (where you are using the child component) like so:

<child [secret]="secret"><child>
like image 137
Sebastian Hildebrandt Avatar answered Aug 09 '26 10:08

Sebastian Hildebrandt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!