Skip to content

Instantly share code, notes, and snippets.

@alirezamirian
Last active September 30, 2017 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alirezamirian/11226faf3d064b191f12e8a2c2a7a1ad to your computer and use it in GitHub Desktop.
Save alirezamirian/11226faf3d064b191f12e8a2c2a7a1ad to your computer and use it in GitHub Desktop.
class RefController {
constructor($element, $scope, $parse, $attrs){
'ngInject';
const tagName = $attrs.refOf || $attrs.$normalize($element[0].tagName.toLowerCase());
let instance = $element.controller(tagName);
if (!instance && !$attrs.refOf) {
instance = $element;
}
$parse($attrs.ref).assign($scope, instance);
}
}
function refDirective() {
return {
restrict: 'A',
controller: RefController
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment