@@ -381,6 +381,47 @@ describe('$compile', function() {
381
381
} )
382
382
} ) ;
383
383
384
+ it ( "should complain when the multi-element end tag can't be found among one of the following siblings" , inject ( function ( $compile ) {
385
+ forEach ( [
386
+ // no content, no end tag
387
+ '<div ng-repeat="item in items" ng-repeat-start></div>' ,
388
+
389
+ // content, no end tag
390
+ '<div ng-repeat="item in items" ng-repeat-start></div>' +
391
+ '<span>{{item.text}}></span>' +
392
+ '<span>{{item.done}}</span>' ,
393
+
394
+ // content, end tag too deep
395
+ '<div ng-repeat="item in items" ng-repeat-start></div>' +
396
+ '<div>' +
397
+ '<span>{{item.text}}></span>' +
398
+ '<span>{{item.done}}</span>' +
399
+ '<span ng-repeat-end></span>' +
400
+ '</div>' ,
401
+
402
+ // content, end tag too high
403
+ '<div>' +
404
+ '<div ng-repeat="item in items" ng-repeat-start></div>' +
405
+ '<span>{{item.text}}></span>' +
406
+ '<span>{{item.done}}</span>' +
407
+ '</div>' +
408
+ '<div ng-repeat-end></div>' ,
409
+
410
+ ] , function ( template ) {
411
+ expect ( function ( ) {
412
+ $compile ( '<div>' + template + '</div>' ) ;
413
+ } ) . toThrow ( "Unmatched ngRepeatStart." ) ;
414
+ } ) ;
415
+ } ) ) ;
416
+
417
+
418
+ it ( "should complain when there is an end attribute at the start of a multi-element directive" , inject ( function ( $compile ) {
419
+ expect ( function ( ) {
420
+ $compile ( '<div><li ng-repeat-end ng-repeat="i in items"></li><li></li></div>' ) ;
421
+ } ) . toThrow ( "Unexpected ngRepeatEnd." ) ;
422
+ } ) ) ;
423
+
424
+
384
425
describe ( 'compiler control' , function ( ) {
385
426
describe ( 'priority' , function ( ) {
386
427
it ( 'should honor priority' , inject ( function ( $compile , $rootScope , log ) {
@@ -2345,6 +2386,35 @@ describe('$compile', function() {
2345
2386
} ) ;
2346
2387
2347
2388
2389
+ it ( 'should compile get templateFn on multi-element' , function ( ) {
2390
+ module ( function ( ) {
2391
+ directive ( 'trans' , function ( log ) {
2392
+ return {
2393
+ transclude : 'multi-element' ,
2394
+ priority : 2 ,
2395
+ controller : function ( $transclude ) { this . $transclude = $transclude ; } ,
2396
+ compile : function ( element , attrs , template ) {
2397
+ log ( 'compile: ' + angular . mock . dump ( element ) ) ;
2398
+ return function ( scope , element , attrs , ctrl ) {
2399
+ log ( 'link' ) ;
2400
+ var cursor = element ;
2401
+ template ( scope . $new ( ) , function ( clone ) { cursor . after ( clone ) ; cursor = clone . eq ( - 1 ) ; } ) ;
2402
+ ctrl . $transclude ( function ( clone ) { cursor . after ( clone ) } ) ;
2403
+ } ;
2404
+ }
2405
+ }
2406
+ } ) ;
2407
+ } ) ;
2408
+ inject ( function ( log , $rootScope , $compile ) {
2409
+ element = $compile ( '<div><div high-log trans="text" trans-start log>{{$parent.$id}}-{{$id}};</div><div trans-end>{{$parent.$id}}-{{$id}};</div></div>' )
2410
+ ( $rootScope ) ;
2411
+ $rootScope . $apply ( ) ;
2412
+ expect ( log ) . toEqual ( 'compile: <!-- trans: text -->; HIGH; link; LOG; LOG' ) ;
2413
+ expect ( element . text ( ) ) . toEqual ( '001-002;001-002;001-003;001-003;' ) ;
2414
+ } ) ;
2415
+ } ) ;
2416
+
2417
+
2348
2418
it ( 'should support transclude directive' , function ( ) {
2349
2419
module ( function ( ) {
2350
2420
directive ( 'trans' , function ( ) {
@@ -2485,6 +2555,30 @@ describe('$compile', function() {
2485
2555
} ) ;
2486
2556
2487
2557
2558
+ it ( 'should support transcluded multi-element on root content' , function ( ) {
2559
+ var comment ;
2560
+ module ( function ( ) {
2561
+ directive ( 'transclude' , valueFn ( {
2562
+ transclude : 'multi-element' ,
2563
+ compile : function ( element , attr , linker ) {
2564
+ return function ( scope , element , attr ) {
2565
+ comment = element ;
2566
+ } ;
2567
+ }
2568
+ } ) ) ;
2569
+ } ) ;
2570
+ inject ( function ( $compile , $rootScope ) {
2571
+ var element = jqLite ( '<div>before<div transclude transclude-begin></div><div transclude-end></div>after</div>' ) . contents ( ) ;
2572
+ expect ( element . length ) . toEqual ( 4 ) ;
2573
+ expect ( nodeName_ ( element [ 1 ] ) ) . toBe ( 'DIV' ) ;
2574
+ $compile ( element ) ( $rootScope ) ;
2575
+ expect ( nodeName_ ( element [ 1 ] ) ) . toBe ( '#comment' ) ;
2576
+ expect ( nodeName_ ( comment ) ) . toBe ( '#comment' ) ;
2577
+ expect ( nodeName_ ( element [ 2 ] ) ) . toBe ( 'DIV' ) ;
2578
+ } ) ;
2579
+ } ) ;
2580
+
2581
+
2488
2582
it ( 'should safely create transclude comment node and not break with "-->"' ,
2489
2583
inject ( function ( $rootScope ) {
2490
2584
// see: https://github.com/angular/angular.js/issues/1740
0 commit comments