@@ -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
/**
@@ -2679,22 +2708,29 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2679
2708
var controller = elementControllers [ name ] ;
2680
2709
var bindings = controllerDirective . $$bindings . bindToController ;
2681
2710
2682
- if ( controller . identifier && bindings ) {
2683
- controller . bindingInfo =
2684
- initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2685
- } else {
2686
- controller . bindingInfo = { } ;
2687
- }
2711
+ if ( preAssignBindingsEnabled ) {
2712
+ if ( controller . identifier && bindings ) {
2713
+ controller . bindingInfo =
2714
+ initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2715
+ } else {
2716
+ controller . bindingInfo = { } ;
2717
+ }
2688
2718
2689
- var controllerResult = controller ( ) ;
2690
- if ( controllerResult !== controller . instance ) {
2691
- // If the controller constructor has a return value, overwrite the instance
2692
- // from setupControllers
2693
- controller . instance = controllerResult ;
2694
- $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2695
- if ( controller . bindingInfo . removeWatches ) {
2696
- controller . bindingInfo . removeWatches ( ) ;
2719
+ var controllerResult = controller ( ) ;
2720
+ if ( controllerResult !== controller . instance ) {
2721
+ // If the controller constructor has a return value, overwrite the instance
2722
+ // from setupControllers
2723
+ controller . instance = controllerResult ;
2724
+ $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2725
+ if ( controller . bindingInfo . removeWatches ) {
2726
+ controller . bindingInfo . removeWatches ( ) ;
2727
+ }
2728
+ controller . bindingInfo =
2729
+ initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2697
2730
}
2731
+ } else {
2732
+ controller . instance = controller ( ) ;
2733
+ $element . data ( '$' + controllerDirective . name + 'Controller' , controller . instance ) ;
2698
2734
controller . bindingInfo =
2699
2735
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2700
2736
}
0 commit comments