Angular 1.5: Accessing a parent component without knowing the parent's name

I am working on 2 components using Angular 1.5.

I want to access the parent from the child and I succeeded using:

require: {
    parent: '^parentCmp'
}

      

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

Thank.

+3


source to share


1 answer


You shouldn't do this :) But if you need to, you can transfer it as normal binding

. Child component:

bindings: {
    parent: '<'
}

      



And in the parent template (I'm assuming you are using an alias $ctrl

for controller

if it doesn't match the name used):

<child-component
    parent="$ctrl"
>
</child-component>

      

+1


source







All Articles