Created
December 7, 2015 16:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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