LBA*_*LBA 6 angularjs angularjs-directive angularjs-components angularjs-1.6
从AngularJs 1.5升级到1.6状态时,$ compile中的更改的文档:
默认情况下禁用对组件/指令控制器实例的预分配绑定,这意味着它们将不再在构造函数内可用.
文档中的升级示例如下(缩写):
之前
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
//...
}
})
Run Code Online (Sandbox Code Playgroud)
后
.component('myComponent', {
bindings: {value: '<'},
controller: function() {
this.$onInit = function() {
// ...
};
}
})
Run Code Online (Sandbox Code Playgroud)
我已经发现我必须使用相同的$ onInit函数为任何使用bindToController的指令: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 () { //...
Run Code Online (Sandbox Code Playgroud)
是否存在受此更改影响的任何其他类型的绑定?
或者用bindToController处理组件和指令是否足够:是吗?
解释相同的问题:在Angular 1.7应用程序中仅使用带有bindToController的指令:false:我是否可以面对有关预分配绑定的任何问题?
当调用 $onInit() 生命周期方法时,绑定完成。这是唯一的保证。假设值在构造函数中可用不再安全,这会影响整个应用程序。
我建议迁移到 1.5 样式组件和 ES6,以便将来更容易迁移。
| 归档时间: |
|
| 查看次数: |
456 次 |
| 最近记录: |