将AngularJs 1.5升级到1.6 - 哪些精确绑定受$ compile reg控制器实例的更改影响?

LBA*_*LBA 6 angularjs angularjs-directive angularjs-components angularjs-1.6

从AngularJs 1.5升级到1.6状态时,$ compile中的更改的文档:

默认情况下禁用对组件/指令控制器实例的预分配绑定,这意味着它们将不再在构造函数内可用.

- AngularJS开发人员指南 - 迁移到V1.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:我是否可以面对有关预分配绑定的任何问题?

Ste*_*erg 0

当调用 $onInit() 生命周期方法时,绑定完成。这是唯一的保证。假设值在构造函数中可用不再安全,这会影响整个应用程序。

我建议迁移到 1.5 样式组件和 ES6,以便将来更容易迁移。