@@ -124,7 +124,7 @@ function MdCompilerProvider($compileProvider) {
124
124
* - `>=1.7` - the compiler calls the constructor first before assigning bindings and
125
125
* `$compileProvider.preAssignBindingsEnabled()` no longer exists.
126
126
*
127
- * The default value is `false` but will change to `true` in AngularJS Material 1.2 .
127
+ * The default value is `false` in to AngularJS 1.6 and earlier but `true` in AngularJS 1.7 .
128
128
*
129
129
* It is recommended to set this flag to `true` in AngularJS Material 1.1.x. The only reason
130
130
* it's not set that way by default is backwards compatibility. Not setting the flag to `true`
@@ -133,9 +133,17 @@ function MdCompilerProvider($compileProvider) {
133
133
* Material Dialog/Panel/Toast/BottomSheet controllers using the `$controller` helper
134
134
* as it always follows the `$compileProvider.preAssignBindingsEnabled()` value.
135
135
*/
136
- // TODO change it to `true` in Material 1.2.
137
- var respectPreAssignBindingsEnabled = false ;
136
+ var respectPreAssignBindingsEnabled ;
137
+ if ( angular . version . major === 1 && angular . version . minor === 7 ) {
138
+ respectPreAssignBindingsEnabled = true ;
139
+ } else {
140
+ respectPreAssignBindingsEnabled = false ;
141
+ }
138
142
this . respectPreAssignBindingsEnabled = function ( respected ) {
143
+ if ( ! respected && angular . version . major === 1 && angular . version . minor === 7 ) {
144
+ throw new Error (
145
+ 'Disabling respectPreAssignBindingsEnabled is not supported in AngularJS 1.7.' ) ;
146
+ }
139
147
if ( angular . isDefined ( respected ) ) {
140
148
respectPreAssignBindingsEnabled = respected ;
141
149
return this ;
@@ -444,27 +452,33 @@ function MdCompilerProvider($compileProvider) {
444
452
445
453
/**
446
454
* Creates and instantiates a new controller with the specified options.
447
- * @param {!Object } options Options that include the controller
455
+ * @param {!Object } options Options that include the controller function or string
448
456
* @param {!Object } injectLocals Locals to to be provided in the controller DI.
449
457
* @param {!Object } locals Locals to be injected to the controller.
450
458
* @returns {!Object } Created controller instance.
451
459
*/
452
460
MdCompilerService . prototype . _createController = function ( options , injectLocals , locals ) {
453
- // The third and fourth arguments to $controller are considered private and are undocumented:
454
- // https://github.com/angular/angular.js/blob/master/src/ng/controller.js#L86
455
- // Passing `true` as the third argument causes `$controller` to return a function that
456
- // gets the controller instance instead returning of the instance directly. When the
457
- // controller is defined as a function, `invokeCtrl.instance` is the *same instance* as
458
- // `invokeCtrl()`. However, then the controller is an ES6 class, `invokeCtrl.instance` is a
459
- // *different instance* from `invokeCtrl()`.
460
- var invokeCtrl = this . $controller ( options . controller , injectLocals , true , options . controllerAs ) ;
461
-
462
- if ( getPreAssignBindingsEnabled ( ) && options . bindToController ) {
463
- angular . extend ( invokeCtrl . instance , locals ) ;
464
- }
461
+ var ctrl ;
462
+ if ( angular . version . major === 1 && angular . version . minor === 7 ) {
463
+ ctrl = this . $controller ( options . controller , injectLocals , options . controllerAs ) ;
464
+ } else {
465
+ // The third and fourth arguments to $controller are considered private and are undocumented
466
+ // in AngularJS prior to 1.7.1:
467
+ // https://github.com/angular/angular.js/blob/v1.6.10/src/ng/controller.js#L102-L109
468
+ // Passing `true` as the third argument causes `$controller` to return a function that
469
+ // gets the controller instance instead of returning the instance directly. When the
470
+ // controller is defined as a function, `invokeCtrl.instance` is the *same instance* as
471
+ // `invokeCtrl()`. However, when the controller is an ES6 class, `invokeCtrl.instance` is a
472
+ // *different instance* from `invokeCtrl()`.
473
+ var invokeCtrl = this . $controller ( options . controller , injectLocals , true , options . controllerAs ) ;
474
+
475
+ if ( getPreAssignBindingsEnabled ( ) && options . bindToController ) {
476
+ angular . extend ( invokeCtrl . instance , locals ) ;
477
+ }
465
478
466
- // Instantiate and initialize the specified controller.
467
- var ctrl = invokeCtrl ( ) ;
479
+ // Instantiate and initialize the specified controller.
480
+ ctrl = invokeCtrl ( ) ;
481
+ }
468
482
469
483
if ( ! getPreAssignBindingsEnabled ( ) && options . bindToController ) {
470
484
angular . extend ( ctrl , locals ) ;
0 commit comments