1

I'm trying to implement this behavior using AngularJS components.

<parent-component>
   <reusable-child-component></reusable-child-component>
</parent-component>

What I want is to pass the parent's controller to the a reusable child component. I know that passing controllers can be done using require attribute but will include the name of the parent's component. (ex. require : '^parentComponent').

Is it possible for me to pass dynamic controller to the child component? That the child component will dynamically receive whatever its parent controller.

<parent-component>
   <reusable-child-component></reusable-child-component>
</parent-component>


<parent2-component>
   <reusable-child-component></reusable-child-component>
</parent2-component>

Need suggestions or help. If possible, written in typescript.

1
  • Why do you need this and why can't you simply use bindings for this purpose? This is not a good idea but you can try to use something like this. Commented Jun 2, 2017 at 10:57

1 Answer 1

1

Just use a binding on the child component like so:

<reusable-child-component my-data="dataFromParentController"></reusable-child-component>

Look at the official documentation for components - https://docs.angularjs.org/guide/component

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.