Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Passing required directive controllers to directive's controller #12989

Closed
timruffles opened this issue Oct 1, 2015 · 1 comment
Closed

Passing required directive controllers to directive's controller #12989

timruffles opened this issue Oct 1, 2015 · 1 comment

Comments

@timruffles
Copy link
Contributor

It's a pain to have to use link to pass other directives' controllers to your own. e.g I want to use a ngModelController instance with a directive that has a controller but no link.

At the people are having to resort to a potentially superfluous link, and some nasty boiler-plate:

app.directive("myThing", function(){
  return {
    require: ["myThing", "ngModel"],
    controller: function(){
      // can't use ngModel here

      this.setNgModel = function() {
      }
    },
    link: function(scope, element, attrs, ctrls){
      var myCtrl = ctrls[0];
      myCtrl.setNgModel(ctrls[1]);
    }
  }
});

It'd be great to have a $controllers local injected variable accessible to the controller.

If this seems a good idea, I'm happy to implement it.

@gkalpak
Copy link
Member

gkalpak commented Oct 1, 2015

Duplicate of #5893.
Closing, since #5893 has more context/discussion.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants