This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 55 * @name ng.directive:ngTransclude
66 *
77 * @description
8- * Insert the transcluded DOM here.
8+ * Directive that marks the insertion point for the transcluded DOM of the nearest parent directive that uses transclusion.
9+ *
10+ * Any existing content of the element that this directive is placed on will be removed before the transcluded content is inserted.
911 *
1012 * @element ANY
1113 *
@@ -58,6 +60,7 @@ var ngTranscludeDirective = ngDirective({
5860
5961 link : function ( $scope , $element , $attrs , controller ) {
6062 controller . $transclude ( function ( clone ) {
63+ $element . html ( '' ) ;
6164 $element . append ( clone ) ;
6265 } ) ;
6366 }
Original file line number Diff line number Diff line change @@ -2450,7 +2450,7 @@ describe('$compile', function() {
24502450 element = $compile ( '<div parent-directive><div child-directive></div>childContentText;</div>' ) ( $rootScope ) ;
24512451 $rootScope . $apply ( ) ;
24522452 expect ( log ) . toEqual ( 'parentController; childController' ) ;
2453- expect ( element . text ( ) ) . toBe ( 'parentTemplateText; childTemplateText;childContentText;' )
2453+ expect ( element . text ( ) ) . toBe ( 'childTemplateText;childContentText;' )
24542454 } ) ;
24552455 } ) ;
24562456
@@ -2554,7 +2554,7 @@ describe('$compile', function() {
25542554 '</div>' ) ( $rootScope ) ;
25552555 $rootScope . $apply ( ) ;
25562556 expect ( log ) . toEqual ( 'parentController; childController; babyController' ) ;
2557- expect ( element . text ( ) ) . toBe ( 'parentTemplateText;childTemplateText; childContentText;babyTemplateText;' )
2557+ expect ( element . text ( ) ) . toBe ( 'childContentText;babyTemplateText;' )
25582558 } ) ;
25592559 } ) ;
25602560
@@ -2825,6 +2825,24 @@ describe('$compile', function() {
28252825 } ) ;
28262826
28272827
2828+ it ( 'should clear contents of the ng-translude element before appending transcluded content' ,
2829+ function ( ) {
2830+ module ( function ( ) {
2831+ directive ( 'trans' , function ( ) {
2832+ return {
2833+ transclude : true ,
2834+ template : '<div ng-transclude>old stuff! </div>'
2835+ } ;
2836+ } ) ;
2837+ } ) ;
2838+ inject ( function ( log , $rootScope , $compile ) {
2839+ element = $compile ( '<div trans>unicorn!</div>' ) ( $rootScope ) ;
2840+ $rootScope . $apply ( ) ;
2841+ expect ( sortedHtml ( element . html ( ) ) ) . toEqual ( '<div ng-transclude=""><span>unicorn!</span></div>' ) ;
2842+ } ) ;
2843+ } ) ;
2844+
2845+
28282846 it ( 'should make the result of a transclusion available to the parent directive in post-linking phase (template)' ,
28292847 function ( ) {
28302848 module ( function ( ) {
You can’t perform that action at this time.
0 commit comments