文档 https://docs.angularjs.org/guide/migration#migrate1.5to1.6-ng-services-%24compile从 AngularJs 1.5 升级到 1.6 时 $compile 的变化如下:
默认情况下禁用组件/指令控制器实例上的预分配绑定,这意味着它们在构造函数中将不再可用。
— AngularJS 开发人员指南 - 迁移到 V1.6 - $compile https://docs.angularjs.org/guide/migration#migrate1.5to1.6-ng-services-%24compile
文档中的升级示例如下(精简):
Before
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
//...
}
})
After
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
this.$onInit = function() {
// ...
};
}
})
我已经发现我必须使用相同的$onInit任何指令的函数使用绑定到控制器:true像这儿:
.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 () { //...
是否有任何其他类型的绑定受到此更改的影响?
或者是否足以应对成分 and 带有 bindToController:true 的指令?
重新表述相同的问题:In an Angular 1.7 application only using带 bindToController 的指令: false:我是否会遇到有关预分配绑定的任何问题?