Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 1.5 : Access parent component without knowing the name of the parent

I am working on 2 components using Angular 1.5.

I want to access the parent from the child, and I managed to do it using :

require: {
    parent: '^parentCmp'
}

The thing is, I would like to do the same, but without "fixing" the parent as "parentCmp", since it won't always be this component I'll have as a parent.

Thanks.

like image 914
Alexandre Couret Avatar asked Oct 29 '22 08:10

Alexandre Couret


1 Answers

You should not do it :) But if you have to, you can pass it as regular binding. Child component:

bindings: {
    parent: '<'
}

And in parent template (I presume that you use $ctrl alias for controller, if it's not true use name you provide):

<child-component
    parent="$ctrl"
>
</child-component>
like image 157
Radek Anuszewski Avatar answered Nov 11 '22 13:11

Radek Anuszewski