angularjs - How do you call a parent directive controller from a child controller (not link method) -


I want to use my parent director from within my child.

I know that if you need a property that you use, then the parent method is passed in the link method as a parameter, but how do I control this controller from my child's controller? I can get it.

Here is a part of a basic example

  // How can I call this init function ?? This.init = function (elem, parentCtrl) {$ scope. $ Element = elem; ParentController = parentCtrl; }  

In the form of this show, I would like to be able to call my childcantrol init () function ...

Thanks in advance

The child's link function will require both controllers, you and their parents, in the child controller, a setParent () The method can be used, which was used to set the original controller. A demo:

  app.directive ("child", function () {return {... requires: ["^ parent", "child"], link: function (scope) , AMM), Attrs, ctrls) {var parent controller = CTRL [0], child controller = CTRL [1]; Child Controller .Setrentant (Parent Controller);}, Controller: ["$ Range", Function ($ Range) {var Parent Controller; = Function (parent) {parentController = parent;}; // use parentController ...}}}}});  

In any case there is a requirement of requirement and the link function is the way to go.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -