@@ -96,19 +96,25 @@ describe('$compile', function() {
96
96
directive ( 'div' , function ( log ) {
97
97
return {
98
98
restrict : 'ECA' ,
99
- link : log . fn ( '1' )
99
+ link : {
100
+ pre : log . fn ( 'pre1' ) ,
101
+ post : log . fn ( 'post1' )
102
+ }
100
103
} ;
101
104
} ) ;
102
105
directive ( 'div' , function ( log ) {
103
106
return {
104
107
restrict : 'ECA' ,
105
- link : log . fn ( '2' )
108
+ link : {
109
+ pre : log . fn ( 'pre2' ) ,
110
+ post : log . fn ( 'post2' )
111
+ }
106
112
} ;
107
113
} ) ;
108
114
} ) ;
109
115
inject ( function ( $compile , $rootScope , log ) {
110
116
element = $compile ( '<div></div>' ) ( $rootScope ) ;
111
- expect ( log ) . toEqual ( '1; 2 ' ) ;
117
+ expect ( log ) . toEqual ( 'pre1; pre2; post2; post1 ' ) ;
112
118
} ) ;
113
119
} ) ;
114
120
} ) ;
@@ -206,7 +212,7 @@ describe('$compile', function() {
206
212
'<span greet="angular" log="L" x-high-log="H" data-medium-log="M"></span>' )
207
213
( $rootScope ) ;
208
214
expect ( element . text ( ) ) . toEqual ( 'Hello angular' ) ;
209
- expect ( log ) . toEqual ( 'H ; M; L ' ) ;
215
+ expect ( log ) . toEqual ( 'L ; M; H ' ) ;
210
216
} ) ) ;
211
217
212
218
@@ -387,7 +393,7 @@ describe('$compile', function() {
387
393
element = $compile (
388
394
'<span log="L" x-high-log="H" data-medium-log="M"></span>' )
389
395
( $rootScope ) ;
390
- expect ( log ) . toEqual ( 'H ; M; L ' ) ;
396
+ expect ( log ) . toEqual ( 'L ; M; H ' ) ;
391
397
} ) ) ;
392
398
} ) ;
393
399
@@ -511,8 +517,7 @@ describe('$compile', function() {
511
517
( $rootScope ) ;
512
518
$rootScope . $digest ( ) ;
513
519
expect ( element . text ( ) ) . toEqual ( 'Replace!' ) ;
514
- // HIGH goes after MEDIUM since it executes as part of replaced template
515
- expect ( log ) . toEqual ( 'MEDIUM; HIGH; LOG' ) ;
520
+ expect ( log ) . toEqual ( 'LOG; HIGH; MEDIUM' ) ;
516
521
} ) ) ;
517
522
518
523
@@ -521,7 +526,7 @@ describe('$compile', function() {
521
526
( $rootScope ) ;
522
527
$rootScope . $digest ( ) ;
523
528
expect ( element . text ( ) ) . toEqual ( 'Append!' ) ;
524
- expect ( log ) . toEqual ( 'HIGH; LOG ; MEDIUM' ) ;
529
+ expect ( log ) . toEqual ( 'LOG; HIGH ; MEDIUM' ) ;
525
530
} ) ) ;
526
531
527
532
@@ -1079,7 +1084,7 @@ describe('$compile', function() {
1079
1084
expect ( log ) . toEqual (
1080
1085
'first-C; FLUSH; second-C; last-C; third-C; ' +
1081
1086
'first-PreL; second-PreL; last-PreL; third-PreL; ' +
1082
- 'third-PostL; first -PostL; second-PostL; last -PostL' ) ;
1087
+ 'third-PostL; last -PostL; second-PostL; first -PostL' ) ;
1083
1088
1084
1089
var span = element . find ( 'span' ) ;
1085
1090
expect ( span . attr ( 'first' ) ) . toEqual ( '' ) ;
@@ -1104,7 +1109,7 @@ describe('$compile', function() {
1104
1109
expect ( log ) . toEqual (
1105
1110
'iFirst-C; FLUSH; iSecond-C; iThird-C; iLast-C; ' +
1106
1111
'iFirst-PreL; iSecond-PreL; iThird-PreL; iLast-PreL; ' +
1107
- 'iFirst -PostL; iSecond -PostL; iThird -PostL; iLast -PostL' ) ;
1112
+ 'iLast -PostL; iThird -PostL; iSecond -PostL; iFirst -PostL' ) ;
1108
1113
1109
1114
var div = element . find ( 'div' ) ;
1110
1115
expect ( div . attr ( 'i-first' ) ) . toEqual ( '' ) ;
@@ -1130,7 +1135,7 @@ describe('$compile', function() {
1130
1135
expect ( log ) . toEqual (
1131
1136
'first-C; FLUSH; second-C; last-C; third-C; ' +
1132
1137
'first-PreL; second-PreL; last-PreL; third-PreL; ' +
1133
- 'third-PostL; first -PostL; second-PostL; last -PostL' ) ;
1138
+ 'third-PostL; last -PostL; second-PostL; first -PostL' ) ;
1134
1139
1135
1140
var span = element . find ( 'span' ) ;
1136
1141
expect ( span . attr ( 'first' ) ) . toEqual ( '' ) ;
@@ -1156,7 +1161,7 @@ describe('$compile', function() {
1156
1161
expect ( log ) . toEqual (
1157
1162
'iFirst-C; FLUSH; iSecond-C; iThird-C; iLast-C; ' +
1158
1163
'iFirst-PreL; iSecond-PreL; iThird-PreL; iLast-PreL; ' +
1159
- 'iFirst -PostL; iSecond -PostL; iThird -PostL; iLast -PostL' ) ;
1164
+ 'iLast -PostL; iThird -PostL; iSecond -PostL; iFirst -PostL' ) ;
1160
1165
1161
1166
var div = element . find ( 'div' ) ;
1162
1167
expect ( div . attr ( 'i-first' ) ) . toEqual ( '' ) ;
@@ -1344,10 +1349,10 @@ describe('$compile', function() {
1344
1349
scope : true ,
1345
1350
restrict : 'CA' ,
1346
1351
compile : function ( ) {
1347
- return function ( scope , element ) {
1352
+ return { pre : function ( scope , element ) {
1348
1353
log ( scope . $id ) ;
1349
1354
expect ( element . data ( '$scope' ) ) . toBe ( scope ) ;
1350
- } ;
1355
+ } } ;
1351
1356
}
1352
1357
} ;
1353
1358
} ) ;
@@ -1409,25 +1414,25 @@ describe('$compile', function() {
1409
1414
directive ( 'log' , function ( log ) {
1410
1415
return {
1411
1416
restrict : 'CA' ,
1412
- link : function ( scope ) {
1417
+ link : { pre : function ( scope ) {
1413
1418
log ( 'log-' + scope . $id + '-' + scope . $parent . $id ) ;
1414
- }
1419
+ } }
1415
1420
} ;
1416
1421
} ) ;
1417
1422
} ) ) ;
1418
1423
1419
1424
1420
1425
it ( 'should allow creation of new scopes' , inject ( function ( $rootScope , $compile , log ) {
1421
1426
element = $compile ( '<div><span scope><a log></a></span></div>' ) ( $rootScope ) ;
1422
- expect ( log ) . toEqual ( 'LOG ; log-002-001; 002 ' ) ;
1427
+ expect ( log ) . toEqual ( '002 ; log-002-001; LOG ' ) ;
1423
1428
expect ( element . find ( 'span' ) . hasClass ( 'ng-scope' ) ) . toBe ( true ) ;
1424
1429
} ) ) ;
1425
1430
1426
1431
1427
1432
it ( 'should allow creation of new isolated scopes for directives' , inject (
1428
1433
function ( $rootScope , $compile , log ) {
1429
1434
element = $compile ( '<div><span iscope><a log></a></span></div>' ) ( $rootScope ) ;
1430
- expect ( log ) . toEqual ( 'LOG; log-002-001; 002' ) ;
1435
+ expect ( log ) . toEqual ( 'log-002-001; LOG ; 002' ) ;
1431
1436
$rootScope . name = 'abc' ;
1432
1437
expect ( iscope . $parent ) . toBe ( $rootScope ) ;
1433
1438
expect ( iscope . name ) . toBeUndefined ( ) ;
@@ -1439,7 +1444,7 @@ describe('$compile', function() {
1439
1444
$httpBackend . expect ( 'GET' , 'tscope.html' ) . respond ( '<a log>{{name}}; scopeId: {{$id}}</a>' ) ;
1440
1445
element = $compile ( '<div><span tscope></span></div>' ) ( $rootScope ) ;
1441
1446
$httpBackend . flush ( ) ;
1442
- expect ( log ) . toEqual ( 'LOG; log-002-001; 002' ) ;
1447
+ expect ( log ) . toEqual ( 'log-002-001; LOG ; 002' ) ;
1443
1448
$rootScope . name = 'Jozo' ;
1444
1449
$rootScope . $apply ( ) ;
1445
1450
expect ( element . text ( ) ) . toBe ( 'Jozo; scopeId: 002' ) ;
@@ -1453,7 +1458,7 @@ describe('$compile', function() {
1453
1458
respond ( '<p><a log>{{name}}; scopeId: {{$id}}</a></p>' ) ;
1454
1459
element = $compile ( '<div><span trscope></span></div>' ) ( $rootScope ) ;
1455
1460
$httpBackend . flush ( ) ;
1456
- expect ( log ) . toEqual ( 'LOG; log-002-001; 002' ) ;
1461
+ expect ( log ) . toEqual ( 'log-002-001; LOG ; 002' ) ;
1457
1462
$rootScope . name = 'Jozo' ;
1458
1463
$rootScope . $apply ( ) ;
1459
1464
expect ( element . text ( ) ) . toBe ( 'Jozo; scopeId: 002' ) ;
@@ -1467,7 +1472,7 @@ describe('$compile', function() {
1467
1472
respond ( '<p><a log>{{name}}; scopeId: {{$id}} |</a></p>' ) ;
1468
1473
element = $compile ( '<div><span ng-repeat="i in [1,2,3]" trscope></span></div>' ) ( $rootScope ) ;
1469
1474
$httpBackend . flush ( ) ;
1470
- expect ( log ) . toEqual ( 'LOG; log-003-002; 003; LOG ; log-005-004; 005; LOG ; log-007-006; 007' ) ;
1475
+ expect ( log ) . toEqual ( 'log-003-002; LOG; 003 ; log-005-004; LOG; 005 ; log-007-006; LOG ; 007' ) ;
1471
1476
$rootScope . name = 'Jozo' ;
1472
1477
$rootScope . $apply ( ) ;
1473
1478
expect ( element . text ( ) ) . toBe ( 'Jozo; scopeId: 003 |Jozo; scopeId: 005 |Jozo; scopeId: 007 |' ) ;
@@ -1481,7 +1486,7 @@ describe('$compile', function() {
1481
1486
$httpBackend . expect ( 'GET' , 'tiscope.html' ) . respond ( '<a log></a>' ) ;
1482
1487
element = $compile ( '<div><span tiscope></span></div>' ) ( $rootScope ) ;
1483
1488
$httpBackend . flush ( ) ;
1484
- expect ( log ) . toEqual ( 'LOG; log-002-001; 002' ) ;
1489
+ expect ( log ) . toEqual ( 'log-002-001; LOG ; 002' ) ;
1485
1490
$rootScope . name = 'abc' ;
1486
1491
expect ( iscope . $parent ) . toBe ( $rootScope ) ;
1487
1492
expect ( iscope . name ) . toBeUndefined ( ) ;
@@ -1501,7 +1506,7 @@ describe('$compile', function() {
1501
1506
'</b>' +
1502
1507
'</div>'
1503
1508
) ( $rootScope ) ;
1504
- expect ( log ) . toEqual ( 'LOG; log-003-002; 003; LOG; log-002-001; 002; LOG ; log-004-001; 004 ' ) ;
1509
+ expect ( log ) . toEqual ( '002; 003; log-003-002; LOG; log-002-001; LOG; 004 ; log-004-001; LOG ' ) ;
1505
1510
} )
1506
1511
) ;
1507
1512
@@ -1571,7 +1576,38 @@ describe('$compile', function() {
1571
1576
$rootScope . $digest ( ) ;
1572
1577
expect ( element . text ( ) ) . toEqual ( 'text: angular' ) ;
1573
1578
expect ( element . attr ( 'name' ) ) . toEqual ( 'attr: angular' ) ;
1574
- } ) ) ;
1579
+ } )
1580
+ ) ;
1581
+
1582
+
1583
+ it ( 'should process attribute interpolation at the beginning of the post-linking phase' , function ( ) {
1584
+ module ( function ( ) {
1585
+ directive ( 'attrLog' , function ( log ) {
1586
+ return {
1587
+ compile : function ( $element , $attrs ) {
1588
+ log ( 'compile=' + $attrs . myName ) ;
1589
+
1590
+ return {
1591
+ pre : function ( $scope , $element , $attrs ) {
1592
+ log ( 'preLink=' + $attrs . myName ) ;
1593
+ } ,
1594
+ post : function ( $scope , $element ) {
1595
+ log ( 'postLink=' + $attrs . myName ) ;
1596
+ }
1597
+ }
1598
+ }
1599
+ }
1600
+ } )
1601
+ } ) ;
1602
+ inject ( function ( $rootScope , $compile , log ) {
1603
+ element = $compile ( '<div attr-log my-name="{{name}}"></div>' ) ( $rootScope ) ;
1604
+ $rootScope . name = 'angular' ;
1605
+ $rootScope . $apply ( ) ;
1606
+ log ( 'digest=' + element . attr ( 'my-name' ) ) ;
1607
+ expect ( log ) . toEqual ( 'compile={{name}}; preLink={{name}}; postLink=; digest=angular' ) ;
1608
+ } ) ;
1609
+ } ) ;
1610
+
1575
1611
1576
1612
describe ( 'SCE values' , function ( ) {
1577
1613
it ( 'should resolve compile and link both attribute and text bindings' , inject (
@@ -1753,7 +1789,7 @@ describe('$compile', function() {
1753
1789
it ( 'should compile from top to bottom but link from bottom up' , inject (
1754
1790
function ( $compile , $rootScope , log ) {
1755
1791
element = $compile ( '<a b><c></c></a>' ) ( $rootScope ) ;
1756
- expect ( log ) . toEqual ( 'tA; tB; tC; preA; preB; preC; postC; postA; postB ' ) ;
1792
+ expect ( log ) . toEqual ( 'tA; tB; tC; preA; preB; preC; postC; postB; postA ' ) ;
1757
1793
}
1758
1794
) ) ;
1759
1795
@@ -2230,7 +2266,7 @@ describe('$compile', function() {
2230
2266
} ) ;
2231
2267
inject ( function ( log , $compile , $rootScope ) {
2232
2268
element = $compile ( '<div main dep other></div>' ) ( $rootScope ) ;
2233
- expect ( log ) . toEqual ( 'main ; dep:main; false ' ) ;
2269
+ expect ( log ) . toEqual ( 'false ; dep:main; main ' ) ;
2234
2270
} ) ;
2235
2271
} ) ;
2236
2272
@@ -2639,7 +2675,7 @@ describe('$compile', function() {
2639
2675
element = $compile ( '<div><div high-log trans="text" log>{{$parent.$id}}-{{$id}};</div></div>' )
2640
2676
( $rootScope ) ;
2641
2677
$rootScope . $apply ( ) ;
2642
- expect ( log ) . toEqual ( 'compile: <!-- trans: text -->; HIGH; link; LOG; LOG' ) ;
2678
+ expect ( log ) . toEqual ( 'compile: <!-- trans: text -->; link; LOG; LOG; HIGH ' ) ;
2643
2679
expect ( element . text ( ) ) . toEqual ( '001-002;001-003;' ) ;
2644
2680
} ) ;
2645
2681
} ) ;
@@ -2907,6 +2943,62 @@ describe('$compile', function() {
2907
2943
} ) ;
2908
2944
2909
2945
2946
+ it ( 'should make the result of a transclusion available to the parent *replace* directive in post-linking phase (template)' ,
2947
+ function ( ) {
2948
+ module ( function ( ) {
2949
+ directive ( 'replacedTrans' , function ( log ) {
2950
+ return {
2951
+ transclude : true ,
2952
+ replace : true ,
2953
+ template : '<div ng-transclude></div>' ,
2954
+ link : {
2955
+ pre : function ( $scope , $element ) {
2956
+ log ( 'pre(' + $element . text ( ) + ')' ) ;
2957
+ } ,
2958
+ post : function ( $scope , $element ) {
2959
+ log ( 'post(' + $element . text ( ) + ')' ) ;
2960
+ }
2961
+ }
2962
+ } ;
2963
+ } ) ;
2964
+ } ) ;
2965
+ inject ( function ( log , $rootScope , $compile ) {
2966
+ element = $compile ( '<div replaced-trans><span>unicorn!</span></div>' ) ( $rootScope ) ;
2967
+ $rootScope . $apply ( ) ;
2968
+ expect ( log ) . toEqual ( 'pre(); post(unicorn!)' ) ;
2969
+ } ) ;
2970
+ } ) ;
2971
+
2972
+
2973
+ it ( 'should make the result of a transclusion available to the parent *replace* directive in post-linking phase (templateUrl)' ,
2974
+ function ( ) {
2975
+ module ( function ( ) {
2976
+ directive ( 'replacedTrans' , function ( log ) {
2977
+ return {
2978
+ transclude : true ,
2979
+ replace : true ,
2980
+ templateUrl : 'trans.html' ,
2981
+ link : {
2982
+ pre : function ( $scope , $element ) {
2983
+ log ( 'pre(' + $element . text ( ) + ')' ) ;
2984
+ } ,
2985
+ post : function ( $scope , $element ) {
2986
+ log ( 'post(' + $element . text ( ) + ')' ) ;
2987
+ }
2988
+ }
2989
+ } ;
2990
+ } ) ;
2991
+ } ) ;
2992
+ inject ( function ( log , $rootScope , $compile , $templateCache ) {
2993
+ $templateCache . put ( 'trans.html' , '<div ng-transclude></div>' ) ;
2994
+
2995
+ element = $compile ( '<div replaced-trans><span>unicorn!</span></div>' ) ( $rootScope ) ;
2996
+ $rootScope . $apply ( ) ;
2997
+ expect ( log ) . toEqual ( 'pre(); post(unicorn!)' ) ;
2998
+ } ) ;
2999
+ } ) ;
3000
+
3001
+
2910
3002
it ( 'should terminate compilation only for element trasclusion' , function ( ) {
2911
3003
module ( function ( ) {
2912
3004
directive ( 'elementTrans' , function ( log ) {
0 commit comments