Documentation for a change in $compile when upgrading from AngularJs 1.5 to 1.6 states:
pre-assigning bindings on component/directive controller instances is disabled by default, which means that they will no longer be available inside the constructors.
The upgrade example in the documentation is as follows (shortened):
Before
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
//...
}
})
After
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
this.$onInit = function() {
// ...
};
}
})
I already discovered that I have to use the same $onInit function for any directive using bindToController: true like here:
.directive('acAllocation', acAllocation);
function acAllocation(SomeService) {
return {
restrict: 'E',
replace: true,
scope: {
allocation: '=acAllocation'
},
controller: acAllocationController,
controllerAs: 'vm',
bindToController: true,
templateUrl: 'path/acAllocation.html'
};
function acAllocationController() {
var vm = this;
this.$onInit = function () { //...
Are there any other types of bindings which are affected by this change?
Or is it enough to deal with components and directives with bindToController:true?
Rephrasing the same question: In an Angular 1.7 application only using directives with bindToController: false: can I face any issues regarding pre-assigning bindings at all?
replace: true
property be avoided. For more information, see Why isreplace
property deprecated in AngularJS directives?. – Costotomy=
should be avoided. It makes the migration to Angular 2+ difficult. For more information, see AngularJS Developer Guide - Component-based application architecture. – Costotomy