Skip to content

Instantly share code, notes, and snippets.

@hsuh
Created March 18, 2015 07:55
Show Gist options
  • Save hsuh/1a087fe39e67aae7910f to your computer and use it in GitHub Desktop.
Save hsuh/1a087fe39e67aae7910f to your computer and use it in GitHub Desktop.
angularjs directive to directive communication (directive's controllers)
app.directive("child", function() {
return {
...
require: ["^parent", "child"],
link: function(scope, elem, attrs, ctrls) {
var parentController = ctrls[0],
childController = ctrls[1];
childController.setParent(parentController);
},
controller: ["$scope", function($scope) {
var parentController;
this.setParent = function(parent) {
parentController = parent;
};
// use parentController...
}]
};
});
http://stackoverflow.com/questions/25075762/how-do-you-call-a-parent-directive-controller-from-a-child-controller-not-link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment