@@ -6892,6 +6892,192 @@ describe('$compile', function() {
6892
6892
} ) ;
6893
6893
6894
6894
} ) ;
6895
+
6896
+ it ( 'should lazily compile the contents of directives that are transcluded' , function ( ) {
6897
+ var innerCompilationCount = 0 , transclude ;
6898
+
6899
+ module ( function ( ) {
6900
+ directive ( 'trans' , valueFn ( {
6901
+ transclude : true ,
6902
+ controller : function ( $transclude ) {
6903
+ transclude = $transclude ;
6904
+ }
6905
+ } ) ) ;
6906
+
6907
+ directive ( 'inner' , valueFn ( {
6908
+ template : '<span>FooBar</span>' ,
6909
+ compile : function ( ) {
6910
+ innerCompilationCount += 1 ;
6911
+ }
6912
+ } ) ) ;
6913
+ } ) ;
6914
+
6915
+ inject ( function ( $compile , $rootScope ) {
6916
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
6917
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
6918
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
6919
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
6920
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
6921
+ } ) ;
6922
+ } ) ;
6923
+
6924
+ it ( 'should lazily compile the contents of directives that are transcluded with a template' , function ( ) {
6925
+ var innerCompilationCount = 0 , transclude ;
6926
+
6927
+ module ( function ( ) {
6928
+ directive ( 'trans' , valueFn ( {
6929
+ transclude : true ,
6930
+ template : '<div>Baz</div>' ,
6931
+ controller : function ( $transclude ) {
6932
+ transclude = $transclude ;
6933
+ }
6934
+ } ) ) ;
6935
+
6936
+ directive ( 'inner' , valueFn ( {
6937
+ template : '<span>FooBar</span>' ,
6938
+ compile : function ( ) {
6939
+ innerCompilationCount += 1 ;
6940
+ }
6941
+ } ) ) ;
6942
+ } ) ;
6943
+
6944
+ inject ( function ( $compile , $rootScope ) {
6945
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
6946
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
6947
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
6948
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
6949
+ expect ( element . text ( ) ) . toBe ( 'BazFooBar' ) ;
6950
+ } ) ;
6951
+ } ) ;
6952
+
6953
+ it ( 'should lazily compile the contents of directives that are transcluded with a templateUrl' , function ( ) {
6954
+ var innerCompilationCount = 0 , transclude ;
6955
+
6956
+ module ( function ( ) {
6957
+ directive ( 'trans' , valueFn ( {
6958
+ transclude : true ,
6959
+ templateUrl : 'baz.html' ,
6960
+ controller : function ( $transclude ) {
6961
+ transclude = $transclude ;
6962
+ }
6963
+ } ) ) ;
6964
+
6965
+ directive ( 'inner' , valueFn ( {
6966
+ template : '<span>FooBar</span>' ,
6967
+ compile : function ( ) {
6968
+ innerCompilationCount += 1 ;
6969
+ }
6970
+ } ) ) ;
6971
+ } ) ;
6972
+
6973
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
6974
+ $httpBackend . expectGET ( 'baz.html' ) . respond ( '<div>Baz</div>' ) ;
6975
+ element = $compile ( '<trans><inner></inner></trans>' ) ( $rootScope ) ;
6976
+ $httpBackend . flush ( ) ;
6977
+
6978
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
6979
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
6980
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
6981
+ expect ( element . text ( ) ) . toBe ( 'BazFooBar' ) ;
6982
+ } ) ;
6983
+ } ) ;
6984
+
6985
+ it ( 'should lazily compile the contents of directives that are transclude element' , function ( ) {
6986
+ var innerCompilationCount = 0 , transclude ;
6987
+
6988
+ module ( function ( ) {
6989
+ directive ( 'trans' , valueFn ( {
6990
+ transclude : 'element' ,
6991
+ controller : function ( $transclude ) {
6992
+ transclude = $transclude ;
6993
+ }
6994
+ } ) ) ;
6995
+
6996
+ directive ( 'inner' , valueFn ( {
6997
+ template : '<span>FooBar</span>' ,
6998
+ compile : function ( ) {
6999
+ innerCompilationCount += 1 ;
7000
+ }
7001
+ } ) ) ;
7002
+ } ) ;
7003
+
7004
+ inject ( function ( $compile , $rootScope ) {
7005
+ element = $compile ( '<div><trans><inner></inner></trans></div>' ) ( $rootScope ) ;
7006
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7007
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7008
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7009
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7010
+ } ) ;
7011
+ } ) ;
7012
+
7013
+ it ( 'should lazily compile transcluded directives with ngIf on them' , function ( ) {
7014
+ var innerCompilationCount = 0 , outerCompilationCount = 0 , transclude ;
7015
+
7016
+ module ( function ( ) {
7017
+ directive ( 'outer' , valueFn ( {
7018
+ transclude : true ,
7019
+ compile : function ( ) {
7020
+ outerCompilationCount += 1 ;
7021
+ } ,
7022
+ controller : function ( $transclude ) {
7023
+ transclude = $transclude ;
7024
+ }
7025
+ } ) ) ;
7026
+
7027
+ directive ( 'inner' , valueFn ( {
7028
+ template : '<span>FooBar</span>' ,
7029
+ compile : function ( ) {
7030
+ innerCompilationCount += 1 ;
7031
+ }
7032
+ } ) ) ;
7033
+ } ) ;
7034
+
7035
+ inject ( function ( $compile , $rootScope ) {
7036
+ $rootScope . shouldCompile = false ;
7037
+
7038
+ element = $compile ( '<div><outer ng-if="shouldCompile"><inner></inner></outer></div>' ) ( $rootScope ) ;
7039
+ expect ( outerCompilationCount ) . toBe ( 0 ) ;
7040
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7041
+ expect ( transclude ) . toBeUndefined ( ) ;
7042
+ $rootScope . $apply ( 'shouldCompile=true' ) ;
7043
+ expect ( outerCompilationCount ) . toBe ( 1 ) ;
7044
+ expect ( innerCompilationCount ) . toBe ( 0 ) ;
7045
+ expect ( transclude ) . toBeDefined ( ) ;
7046
+ transclude ( function ( child ) { element . append ( child ) ; } ) ;
7047
+ expect ( outerCompilationCount ) . toBe ( 1 ) ;
7048
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7049
+ expect ( element . text ( ) ) . toBe ( 'FooBar' ) ;
7050
+ } ) ;
7051
+ } ) ;
7052
+
7053
+ it ( 'should eagerly compile multiple directives with transclusion and templateUrl/replace' , function ( ) {
7054
+ var innerCompilationCount = 0 ;
7055
+
7056
+ module ( function ( ) {
7057
+ directive ( 'outer' , valueFn ( {
7058
+ transclude : true
7059
+ } ) ) ;
7060
+
7061
+ directive ( 'outer' , valueFn ( {
7062
+ templateUrl : 'inner.html' ,
7063
+ replace : true
7064
+ } ) ) ;
7065
+
7066
+ directive ( 'inner' , valueFn ( {
7067
+ compile : function ( ) {
7068
+ innerCompilationCount += 1 ;
7069
+ }
7070
+ } ) ) ;
7071
+ } ) ;
7072
+
7073
+ inject ( function ( $compile , $rootScope , $httpBackend ) {
7074
+ $httpBackend . expectGET ( 'inner.html' ) . respond ( '<inner></inner>' ) ;
7075
+ element = $compile ( '<outer></outer>' ) ( $rootScope ) ;
7076
+ $httpBackend . flush ( ) ;
7077
+
7078
+ expect ( innerCompilationCount ) . toBe ( 1 ) ;
7079
+ } ) ;
7080
+ } ) ;
6895
7081
} ) ;
6896
7082
6897
7083
0 commit comments