This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 5
5
* @name ng.directive:ngTransclude
6
6
*
7
7
* @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.
9
11
*
10
12
* @element ANY
11
13
*
@@ -58,6 +60,7 @@ var ngTranscludeDirective = ngDirective({
58
60
59
61
link : function ( $scope , $element , $attrs , controller ) {
60
62
controller . $transclude ( function ( clone ) {
63
+ $element . html ( '' ) ;
61
64
$element . append ( clone ) ;
62
65
} ) ;
63
66
}
Original file line number Diff line number Diff line change @@ -2450,7 +2450,7 @@ describe('$compile', function() {
2450
2450
element = $compile ( '<div parent-directive><div child-directive></div>childContentText;</div>' ) ( $rootScope ) ;
2451
2451
$rootScope . $apply ( ) ;
2452
2452
expect ( log ) . toEqual ( 'parentController; childController' ) ;
2453
- expect ( element . text ( ) ) . toBe ( 'parentTemplateText; childTemplateText;childContentText;' )
2453
+ expect ( element . text ( ) ) . toBe ( 'childTemplateText;childContentText;' )
2454
2454
} ) ;
2455
2455
} ) ;
2456
2456
@@ -2554,7 +2554,7 @@ describe('$compile', function() {
2554
2554
'</div>' ) ( $rootScope ) ;
2555
2555
$rootScope . $apply ( ) ;
2556
2556
expect ( log ) . toEqual ( 'parentController; childController; babyController' ) ;
2557
- expect ( element . text ( ) ) . toBe ( 'parentTemplateText;childTemplateText; childContentText;babyTemplateText;' )
2557
+ expect ( element . text ( ) ) . toBe ( 'childContentText;babyTemplateText;' )
2558
2558
} ) ;
2559
2559
} ) ;
2560
2560
@@ -2825,6 +2825,24 @@ describe('$compile', function() {
2825
2825
} ) ;
2826
2826
2827
2827
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
+
2828
2846
it ( 'should make the result of a transclusion available to the parent directive in post-linking phase (template)' ,
2829
2847
function ( ) {
2830
2848
module ( function ( ) {
You can’t perform that action at this time.
0 commit comments