Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 528e98f

Browse files
committed
feat($compile): remove the preAssignBindingsEnabled flag
BREAKING CHANGE: Previously, the $compileProvider.preAssignBindingsEnabled flag was supported. To migrate your code: 1) If you specified `$compileProvider.preAssignBindingsEnabled(true)`, you can remove that statement - since AngularJS 1.6.0 this is the default so your app should still work even in AngularJS 1.6 after such removal. Afterwards, migrating to AngularJS 1.7.0 shouldn't require any further action. 2) If you specified `$compileProvider.preAssignBindingsEnabled(true)`, first migrate your code so that the flag can be flipped to `false`. The instructions on how to do that are available in the "Migrating from 1.5 to 1.6" guide: https://docs.angularjs.org/guide/migration#migrating-from-1-5-to-1-6
1 parent 6ccbfa6 commit 528e98f

File tree

4 files changed

+5467
-5739
lines changed

4 files changed

+5467
-5739
lines changed

Diff for: src/ng/compile.js

+4-56
Original file line numberDiff line numberDiff line change
@@ -1372,36 +1372,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13721372
return debugInfoEnabled;
13731373
};
13741374

1375-
/**
1376-
* @ngdoc method
1377-
* @name $compileProvider#preAssignBindingsEnabled
1378-
*
1379-
* @param {boolean=} enabled update the preAssignBindingsEnabled state if provided, otherwise just return the
1380-
* current preAssignBindingsEnabled state
1381-
* @returns {*} current value if used as getter or itself (chaining) if used as setter
1382-
*
1383-
* @kind function
1384-
*
1385-
* @description
1386-
* Call this method to enable/disable whether directive controllers are assigned bindings before
1387-
* calling the controller's constructor.
1388-
* If enabled (true), the compiler assigns the value of each of the bindings to the
1389-
* properties of the controller object before the constructor of this object is called.
1390-
*
1391-
* If disabled (false), the compiler calls the constructor first before assigning bindings.
1392-
*
1393-
* The default value is true in AngularJS 1.5.x but will switch to false in AngularJS 1.6.x.
1394-
*/
1395-
var preAssignBindingsEnabled = false;
1396-
this.preAssignBindingsEnabled = function(enabled) {
1397-
if (isDefined(enabled)) {
1398-
preAssignBindingsEnabled = enabled;
1399-
return this;
1400-
}
1401-
return preAssignBindingsEnabled;
1402-
};
1403-
1404-
14051375
var TTL = 10;
14061376
/**
14071377
* @ngdoc method
@@ -2722,33 +2692,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27222692
var controller = elementControllers[name];
27232693
var bindings = controllerDirective.$$bindings.bindToController;
27242694

2725-
if (preAssignBindingsEnabled) {
2726-
if (bindings) {
2727-
controller.bindingInfo =
2728-
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
2729-
} else {
2730-
controller.bindingInfo = {};
2731-
}
2732-
2733-
var controllerResult = controller();
2734-
if (controllerResult !== controller.instance) {
2735-
// If the controller constructor has a return value, overwrite the instance
2736-
// from setupControllers
2737-
controller.instance = controllerResult;
2738-
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
2739-
if (controller.bindingInfo.removeWatches) {
2740-
controller.bindingInfo.removeWatches();
2741-
}
2742-
controller.bindingInfo =
2743-
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
2744-
}
2745-
} else {
2746-
controller.instance = controller();
2747-
$element.data('$' + controllerDirective.name + 'Controller', controller.instance);
2748-
controller.bindingInfo =
2749-
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
2695+
controller.instance = controller();
2696+
$element.data('$' + controllerDirective.name + 'Controller', controller.instance);
2697+
controller.bindingInfo =
2698+
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
27502699
}
2751-
}
27522700

27532701
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
27542702
forEach(controllerDirectives, function(controllerDirective, name) {

Diff for: src/ngMock/angular-mocks.js

+2-16
Original file line numberDiff line numberDiff line change
@@ -2207,11 +2207,6 @@ angular.mock.$RootElementProvider = function() {
22072207
* A decorator for {@link ng.$controller} with additional `bindings` parameter, useful when testing
22082208
* controllers of directives that use {@link $compile#-bindtocontroller- `bindToController`}.
22092209
*
2210-
* Depending on the value of
2211-
* {@link ng.$compileProvider#preAssignBindingsEnabled `preAssignBindingsEnabled()`}, the properties
2212-
* will be bound before or after invoking the constructor.
2213-
*
2214-
*
22152210
* ## Example
22162211
*
22172212
* ```js
@@ -2267,22 +2262,13 @@ angular.mock.$RootElementProvider = function() {
22672262
* the `bindToController` feature and simplify certain kinds of tests.
22682263
* @return {Object} Instance of given controller.
22692264
*/
2270-
function createControllerDecorator(compileProvider) {
2265+
function createControllerDecorator() {
22712266
angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
22722267
return function(expression, locals, later, ident) {
22732268
if (later && typeof later === 'object') {
2274-
var preAssignBindingsEnabled = compileProvider.preAssignBindingsEnabled();
2275-
22762269
var instantiate = $delegate(expression, locals, true, ident);
2277-
if (preAssignBindingsEnabled) {
2278-
angular.extend(instantiate.instance, later);
2279-
}
2280-
22812270
var instance = instantiate();
2282-
if (!preAssignBindingsEnabled || instance !== instantiate.instance) {
2283-
angular.extend(instance, later);
2284-
}
2285-
2271+
angular.extend(instance, later);
22862272
return instance;
22872273
}
22882274
return $delegate(expression, locals, later, ident);

0 commit comments

Comments
 (0)