Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created December 7, 2015 16:22
Show Gist options
  • Save timruffles/204fd03f50077e3400d7 to your computer and use it in GitHub Desktop.
Save timruffles/204fd03f50077e3400d7 to your computer and use it in GitHub Desktop.
if a directive has a need to collaborate with an element up the tree, use this to make that relationship explicit and testable
/**
* if a directive has a need to collaborate with
* an element up the tree, use this to make that
* relationship explicit and testable
*
* ```html
* <div named-element="someCtrl.someElement">
* </div>
* <some-crazy-component element="someCtrl.someElement">
* </some-crazy-component>
* ```
*
*/
!(function() {
"use strict";
angular.module('something')
.directive("namedElement", get)
function get(
directiveHelpers
) {
return {
restrict: "A",
link: function(scope, el, attrs) {
directiveHelpers.set(scope, attrs.namedElement, el[0]);
},
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment