@@ -1369,6 +1369,35 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1369
1369
return debugInfoEnabled ;
1370
1370
} ;
1371
1371
1372
+ /**
1373
+ * @ngdoc method
1374
+ * @name $compileProvider#preAssignBindingsEnabled
1375
+ *
1376
+ * @param {boolean= } enabled update the preAssignBindingsEnabled state if provided, otherwise just return the
1377
+ * current preAssignBindingsEnabled state
1378
+ * @returns {* } current value if used as getter or itself (chaining) if used as setter
1379
+ *
1380
+ * @kind function
1381
+ *
1382
+ * @description
1383
+ * Call this method to enable/disable whether directive controllers are assigned bindings before
1384
+ * calling the controller's constructor.
1385
+ * If enabled (true), the compiler assigns the value of each of the bindings to the
1386
+ * properties of the controller object before the constructor of this object is called.
1387
+ *
1388
+ * If disabled (false), the compiler calls the constructor first before assigning bindings.
1389
+ *
1390
+ * The default value is true in Angular 1.5.x but will switch to false in Angular 1.6.x.
1391
+ */
1392
+ var preAssignBindingsEnabled = true ;
1393
+ this . preAssignBindingsEnabled = function ( enabled ) {
1394
+ if ( isDefined ( enabled ) ) {
1395
+ preAssignBindingsEnabled = enabled ;
1396
+ return this ;
1397
+ }
1398
+ return preAssignBindingsEnabled ;
1399
+ } ;
1400
+
1372
1401
1373
1402
var TTL = 10 ;
1374
1403
/**
@@ -2656,22 +2685,29 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2656
2685
var controller = elementControllers [ name ] ;
2657
2686
var bindings = controllerDirective . $$bindings . bindToController ;
2658
2687
2659
- if ( controller . identifier && bindings ) {
2660
- controller . bindingInfo =
2661
- initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2662
- } else {
2663
- controller . bindingInfo = { } ;
2664
- }
2688
+ if ( preAssignBindingsEnabled ) {
2689
+ if ( controller . identifier && bindings ) {
2690
+ controller . bindingInfo =
2691
+ initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2692
+ } else {
2693
+ controller . bindingInfo = { } ;
2694
+ }
2665
2695
2666
- var controllerResult = controller ( ) ;
2667
- if ( controllerResult !== controller . instance ) {
2668
- // If the controller constructor has a return value, overwrite the instance
2669
- // from setupControllers
2670
- controller . instance = controllerResult ;
2671
- $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2672
- if ( controller . bindingInfo . removeWatches ) {
2673
- controller . bindingInfo . removeWatches ( ) ;
2696
+ var controllerResult = controller ( ) ;
2697
+ if ( controllerResult !== controller . instance ) {
2698
+ // If the controller constructor has a return value, overwrite the instance
2699
+ // from setupControllers
2700
+ controller . instance = controllerResult ;
2701
+ $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2702
+ if ( controller . bindingInfo . removeWatches ) {
2703
+ controller . bindingInfo . removeWatches ( ) ;
2704
+ }
2705
+ controller . bindingInfo =
2706
+ initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2674
2707
}
2708
+ } else {
2709
+ controller . instance = controller ( ) ;
2710
+ $element . data ( '$' + controllerDirective . name + 'Controller' , controller . instance ) ;
2675
2711
controller . bindingInfo =
2676
2712
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2677
2713
}
0 commit comments