Skip to content

Instantly share code, notes, and snippets.

@pratyushmittal
Created June 25, 2015 07:00
Show Gist options
  • Save pratyushmittal/92d1c5ca8f012cff074a to your computer and use it in GitHub Desktop.
Save pratyushmittal/92d1c5ca8f012cff074a to your computer and use it in GitHub Desktop.
AngularJS - Adding content outside ng-view
function block($document) {
function blockLink(scope, elem, attrs) {
var element = elem[0];
element.removeAttribute('block');
element.removeAttribute('target');
var targetTag = 'block-' + attrs.target;
var blockElem = angular.element($document).find(targetTag)[0];
blockElem.innerHTML = '';
blockElem.appendChild(element);
scope.$on('$destroy', function() {
blockElem.innerHTML = '';
});
}
return {
restrict: 'A',
link: blockLink
};
}
angular.module('app.directives', [])
.directive('block', block);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment