The following directive extends the functionality of the ng-include directive.
It adds an event listener to replace the original item when the content is ready and loaded.
Use it in the original way, just add the "replace" attribute:
<ng-include src="'src.html'" replace></ng-include>
or with attribute designation:
<div ng-include="'src.html'" replace></div>
Here is the directive (don't forget to include the include-replace module as a dependency):
angular.module('include-replace', []).directive('ngInclude', function () { return { priority: 1000, link: function($scope, $element, $attrs){ if($attrs.replace !== undefined){ var src = $scope.$eval($attrs.ngInclude || $attrs.src); var unbind = $scope.$on('$includeContentLoaded', function($event, loaded_src){ if(src === loaded_src){ $element.next().replaceWith($element.next().children()); unbind(); }; }); } } }; });
edrian May 26 '16 at 14:59 2016-05-26 14:59
source share