Created
June 25, 2015 07:00
-
-
Save pratyushmittal/92d1c5ca8f012cff074a to your computer and use it in GitHub Desktop.
AngularJS - Adding content outside ng-view
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
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