@@ -1369,6 +1369,35 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13691369 return debugInfoEnabled ;
13701370 } ;
13711371
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+
13721401
13731402 var TTL = 10 ;
13741403 /**
@@ -2666,22 +2695,29 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26662695 var controller = elementControllers [ name ] ;
26672696 var bindings = controllerDirective . $$bindings . bindToController ;
26682697
2669- if ( controller . identifier && bindings ) {
2670- controller . bindingInfo =
2671- initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2672- } else {
2673- controller . bindingInfo = { } ;
2674- }
2698+ if ( preAssignBindingsEnabled ) {
2699+ if ( controller . identifier && bindings ) {
2700+ controller . bindingInfo =
2701+ initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2702+ } else {
2703+ controller . bindingInfo = { } ;
2704+ }
26752705
2676- var controllerResult = controller ( ) ;
2677- if ( controllerResult !== controller . instance ) {
2678- // If the controller constructor has a return value, overwrite the instance
2679- // from setupControllers
2680- controller . instance = controllerResult ;
2681- $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2682- if ( controller . bindingInfo . removeWatches ) {
2683- controller . bindingInfo . removeWatches ( ) ;
2706+ var controllerResult = controller ( ) ;
2707+ if ( controllerResult !== controller . instance ) {
2708+ // If the controller constructor has a return value, overwrite the instance
2709+ // from setupControllers
2710+ controller . instance = controllerResult ;
2711+ $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2712+ if ( controller . bindingInfo . removeWatches ) {
2713+ controller . bindingInfo . removeWatches ( ) ;
2714+ }
2715+ controller . bindingInfo =
2716+ initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
26842717 }
2718+ } else {
2719+ controller . instance = controller ( ) ;
2720+ $element . data ( '$' + controllerDirective . name + 'Controller' , controller . instance ) ;
26852721 controller . bindingInfo =
26862722 initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
26872723 }
0 commit comments