@@ -3845,10 +3845,10 @@ describe('$compile', function() {
3845
3845
} ) ;
3846
3846
} ) ;
3847
3847
3848
- forEach ( [ true , false ] , function ( preAssignBindings ) {
3849
- describe ( ( preAssignBindings ? 'with' : 'without' ) + ' pre-assigned bindings' , function ( ) {
3848
+ forEach ( [ true , false ] , function ( preAssignBindingsEnabled ) {
3849
+ describe ( ( preAssignBindingsEnabled ? 'with' : 'without' ) + ' pre-assigned bindings' , function ( ) {
3850
3850
beforeEach ( module ( function ( $compileProvider ) {
3851
- $compileProvider . preAssignBindings ( preAssignBindings ) ;
3851
+ $compileProvider . preAssignBindingsEnabled ( preAssignBindingsEnabled ) ;
3852
3852
} ) ) ;
3853
3853
3854
3854
describe ( 'controller lifecycle hooks' , function ( ) {
@@ -5716,7 +5716,7 @@ describe('$compile', function() {
5716
5716
expect ( this . str ) . toBe ( 'Hello, world!' ) ;
5717
5717
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
5718
5718
} ;
5719
- if ( preAssignBindings ) {
5719
+ if ( preAssignBindingsEnabled ) {
5720
5720
this . check ( ) ;
5721
5721
} else {
5722
5722
this . $onInit = this . check ;
@@ -5742,6 +5742,104 @@ describe('$compile', function() {
5742
5742
} ) ;
5743
5743
5744
5744
5745
+ it ( 'should not pre-assign bound properties to the controller if `preAssignBindingsEnabled` is disabled' , function ( ) {
5746
+ var controllerCalled = false , onInitCalled = false ;
5747
+ module ( function ( $compileProvider ) {
5748
+ $compileProvider . preAssignBindingsEnabled ( false ) ;
5749
+ $compileProvider . directive ( 'fooDir' , valueFn ( {
5750
+ template : '<p>isolate</p>' ,
5751
+ scope : {
5752
+ 'data' : '=dirData' ,
5753
+ 'oneway' : '<dirData' ,
5754
+ 'str' : '@dirStr' ,
5755
+ 'fn' : '&dirFn'
5756
+ } ,
5757
+ controller : function ( $scope ) {
5758
+ expect ( this . data ) . toBeUndefined ( ) ;
5759
+ expect ( this . oneway ) . toBeUndefined ( ) ;
5760
+ expect ( this . str ) . toBeUndefined ( ) ;
5761
+ expect ( this . fn ) . toBeUndefined ( ) ;
5762
+ controllerCalled = true ;
5763
+ this . $onInit = function ( ) {
5764
+ expect ( this . data ) . toEqualData ( {
5765
+ 'foo' : 'bar' ,
5766
+ 'baz' : 'biz'
5767
+ } ) ;
5768
+ expect ( this . oneway ) . toEqualData ( {
5769
+ 'foo' : 'bar' ,
5770
+ 'baz' : 'biz'
5771
+ } ) ;
5772
+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
5773
+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
5774
+ onInitCalled = true ;
5775
+ } ;
5776
+ } ,
5777
+ controllerAs : 'test' ,
5778
+ bindToController : true
5779
+ } ) ) ;
5780
+ } ) ;
5781
+ inject ( function ( $compile , $rootScope ) {
5782
+ $rootScope . fn = valueFn ( 'called!' ) ;
5783
+ $rootScope . whom = 'world' ;
5784
+ $rootScope . remoteData = {
5785
+ 'foo' : 'bar' ,
5786
+ 'baz' : 'biz'
5787
+ } ;
5788
+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
5789
+ 'dir-str="Hello, {{whom}}!" ' +
5790
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
5791
+ expect ( controllerCalled ) . toBe ( true ) ;
5792
+ expect ( onInitCalled ) . toBe ( true ) ;
5793
+ } ) ;
5794
+ } ) ;
5795
+
5796
+ it ( 'should pre-assign bound properties to the controller if `preAssignBindingsEnabled` is enabled' , function ( ) {
5797
+ var controllerCalled = false , onInitCalled = false ;
5798
+ module ( function ( $compileProvider ) {
5799
+ $compileProvider . preAssignBindingsEnabled ( true ) ;
5800
+ $compileProvider . directive ( 'fooDir' , valueFn ( {
5801
+ template : '<p>isolate</p>' ,
5802
+ scope : {
5803
+ 'data' : '=dirData' ,
5804
+ 'oneway' : '<dirData' ,
5805
+ 'str' : '@dirStr' ,
5806
+ 'fn' : '&dirFn'
5807
+ } ,
5808
+ controller : function ( $scope ) {
5809
+ expect ( this . data ) . toEqualData ( {
5810
+ 'foo' : 'bar' ,
5811
+ 'baz' : 'biz'
5812
+ } ) ;
5813
+ expect ( this . oneway ) . toEqualData ( {
5814
+ 'foo' : 'bar' ,
5815
+ 'baz' : 'biz'
5816
+ } ) ;
5817
+ expect ( this . str ) . toBe ( 'Hello, world!' ) ;
5818
+ expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
5819
+ controllerCalled = true ;
5820
+ this . $onInit = function ( ) {
5821
+ onInitCalled = true ;
5822
+ } ;
5823
+ } ,
5824
+ controllerAs : 'test' ,
5825
+ bindToController : true
5826
+ } ) ) ;
5827
+ } ) ;
5828
+ inject ( function ( $compile , $rootScope ) {
5829
+ $rootScope . fn = valueFn ( 'called!' ) ;
5830
+ $rootScope . whom = 'world' ;
5831
+ $rootScope . remoteData = {
5832
+ 'foo' : 'bar' ,
5833
+ 'baz' : 'biz'
5834
+ } ;
5835
+ element = $compile ( '<div foo-dir dir-data="remoteData" ' +
5836
+ 'dir-str="Hello, {{whom}}!" ' +
5837
+ 'dir-fn="fn()"></div>' ) ( $rootScope ) ;
5838
+ expect ( controllerCalled ) . toBe ( true ) ;
5839
+ expect ( onInitCalled ) . toBe ( true ) ;
5840
+ } ) ;
5841
+ } ) ;
5842
+
5745
5843
it ( 'should eventually expose isolate scope variables on ES6 class controller with controllerAs when bindToController is true' , function ( ) {
5746
5844
if ( ! / c h r o m e / i. test ( window . navigator . userAgent ) ) return ;
5747
5845
var controllerCalled = false ;
@@ -5846,7 +5944,7 @@ describe('$compile', function() {
5846
5944
expect ( this . str ) . toBe ( 'Hello, world!' ) ;
5847
5945
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
5848
5946
} ;
5849
- if ( preAssignBindings ) {
5947
+ if ( preAssignBindingsEnabled ) {
5850
5948
this . check ( ) ;
5851
5949
} else {
5852
5950
this . $onInit = this . check ;
@@ -5993,7 +6091,7 @@ describe('$compile', function() {
5993
6091
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
5994
6092
} ;
5995
6093
controllerCalled = true ;
5996
- if ( preAssignBindings ) {
6094
+ if ( preAssignBindingsEnabled ) {
5997
6095
this . check ( ) ;
5998
6096
} else {
5999
6097
this . $onInit = this . check ;
@@ -6045,7 +6143,7 @@ describe('$compile', function() {
6045
6143
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6046
6144
} ;
6047
6145
controllerCalled = true ;
6048
- if ( preAssignBindings ) {
6146
+ if ( preAssignBindingsEnabled ) {
6049
6147
this . check ( ) ;
6050
6148
} else {
6051
6149
this . $onInit = this . check ;
@@ -6100,7 +6198,7 @@ describe('$compile', function() {
6100
6198
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6101
6199
} ;
6102
6200
controller1Called = true ;
6103
- if ( preAssignBindings ) {
6201
+ if ( preAssignBindingsEnabled ) {
6104
6202
this . check ( ) ;
6105
6203
} else {
6106
6204
this . $onInit = this . check ;
@@ -6123,7 +6221,7 @@ describe('$compile', function() {
6123
6221
expect ( this . fn ( ) ) . toBe ( 'second called!' ) ;
6124
6222
} ;
6125
6223
controller2Called = true ;
6126
- if ( preAssignBindings ) {
6224
+ if ( preAssignBindingsEnabled ) {
6127
6225
this . check ( ) ;
6128
6226
} else {
6129
6227
this . $onInit = this . check ;
@@ -6177,7 +6275,7 @@ describe('$compile', function() {
6177
6275
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6178
6276
} ;
6179
6277
controller1Called = true ;
6180
- if ( preAssignBindings ) {
6278
+ if ( preAssignBindingsEnabled ) {
6181
6279
this . check ( ) ;
6182
6280
} else {
6183
6281
this . $onInit = this . check ;
@@ -6200,7 +6298,7 @@ describe('$compile', function() {
6200
6298
expect ( this . fn ( ) ) . toBe ( 'second called!' ) ;
6201
6299
} ;
6202
6300
controller2Called = true ;
6203
- if ( preAssignBindings ) {
6301
+ if ( preAssignBindingsEnabled ) {
6204
6302
this . check ( ) ;
6205
6303
} else {
6206
6304
this . $onInit = this . check ;
@@ -6254,7 +6352,7 @@ describe('$compile', function() {
6254
6352
expect ( this . fn ( ) ) . toBe ( 'called!' ) ;
6255
6353
} ;
6256
6354
controller1Called = true ;
6257
- if ( preAssignBindings ) {
6355
+ if ( preAssignBindingsEnabled ) {
6258
6356
this . check ( ) ;
6259
6357
} else {
6260
6358
this . $onInit = this . check ;
@@ -6278,7 +6376,7 @@ describe('$compile', function() {
6278
6376
expect ( this . fn ( ) ) . toBe ( 'second called!' ) ;
6279
6377
} ;
6280
6378
controller2Called = true ;
6281
- if ( preAssignBindings ) {
6379
+ if ( preAssignBindingsEnabled ) {
6282
6380
this . check ( ) ;
6283
6381
} else {
6284
6382
this . $onInit = this . check ;
@@ -6598,7 +6696,7 @@ describe('$compile', function() {
6598
6696
this . initProp = function ( ) {
6599
6697
this . prop = this . prop || 'default' ;
6600
6698
} ;
6601
- if ( preAssignBindings ) {
6699
+ if ( preAssignBindingsEnabled ) {
6602
6700
this . initProp ( ) ;
6603
6701
} else {
6604
6702
this . $onInit = this . initProp ;
@@ -6636,7 +6734,7 @@ describe('$compile', function() {
6636
6734
this . getProp = function ( ) {
6637
6735
return self . prop ;
6638
6736
} ;
6639
- if ( preAssignBindings ) {
6737
+ if ( preAssignBindingsEnabled ) {
6640
6738
this . initProp ( ) ;
6641
6739
} else {
6642
6740
this . $onInit = this . initProp ;
0 commit comments