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

fix($compile): remove the preAssignBindingsEnabled flag #15782

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 4 additions & 56 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1372,36 +1372,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return debugInfoEnabled;
};

/**
* @ngdoc method
* @name $compileProvider#preAssignBindingsEnabled
*
* @param {boolean=} enabled update the preAssignBindingsEnabled state if provided, otherwise just return the
* current preAssignBindingsEnabled state
* @returns {*} current value if used as getter or itself (chaining) if used as setter
*
* @kind function
*
* @description
* Call this method to enable/disable whether directive controllers are assigned bindings before
* calling the controller's constructor.
* If enabled (true), the compiler assigns the value of each of the bindings to the
* properties of the controller object before the constructor of this object is called.
*
* If disabled (false), the compiler calls the constructor first before assigning bindings.
*
* The default value is true in AngularJS 1.5.x but will switch to false in AngularJS 1.6.x.
*/
var preAssignBindingsEnabled = false;
this.preAssignBindingsEnabled = function(enabled) {
if (isDefined(enabled)) {
preAssignBindingsEnabled = enabled;
return this;
}
return preAssignBindingsEnabled;
};


var TTL = 10;
/**
* @ngdoc method
Expand Down Expand Up @@ -2722,33 +2692,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
var controller = elementControllers[name];
var bindings = controllerDirective.$$bindings.bindToController;

if (preAssignBindingsEnabled) {
if (bindings) {
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
} else {
controller.bindingInfo = {};
}

var controllerResult = controller();
if (controllerResult !== controller.instance) {
// If the controller constructor has a return value, overwrite the instance
// from setupControllers
controller.instance = controllerResult;
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
if (controller.bindingInfo.removeWatches) {
controller.bindingInfo.removeWatches();
}
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
}
} else {
controller.instance = controller();
$element.data('$' + controllerDirective.name + 'Controller', controller.instance);
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
controller.instance = controller();
$element.data('$' + controllerDirective.name + 'Controller', controller.instance);
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
}
}

// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
forEach(controllerDirectives, function(controllerDirective, name) {
Expand Down
18 changes: 2 additions & 16 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2207,11 +2207,6 @@ angular.mock.$RootElementProvider = function() {
* A decorator for {@link ng.$controller} with additional `bindings` parameter, useful when testing
* controllers of directives that use {@link $compile#-bindtocontroller- `bindToController`}.
*
* Depending on the value of
* {@link ng.$compileProvider#preAssignBindingsEnabled `preAssignBindingsEnabled()`}, the properties
* will be bound before or after invoking the constructor.
*
*
* ## Example
*
* ```js
Expand Down Expand Up @@ -2267,22 +2262,13 @@ angular.mock.$RootElementProvider = function() {
* the `bindToController` feature and simplify certain kinds of tests.
* @return {Object} Instance of given controller.
*/
function createControllerDecorator(compileProvider) {
function createControllerDecorator() {
angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
return function(expression, locals, later, ident) {
if (later && typeof later === 'object') {
var preAssignBindingsEnabled = compileProvider.preAssignBindingsEnabled();

var instantiate = $delegate(expression, locals, true, ident);
if (preAssignBindingsEnabled) {
angular.extend(instantiate.instance, later);
}

var instance = instantiate();
if (!preAssignBindingsEnabled || instance !== instantiate.instance) {
angular.extend(instance, later);
}

angular.extend(instance, later);
return instance;
}
return $delegate(expression, locals, later, ident);
Expand Down
Loading