Angularjs 请求$scope来愚弄BC控制器模块

Angularjs 请求$scope来愚弄BC控制器模块,angularjs,angularjs-directive,comments,Angularjs,Angularjs Directive,Comments,在指令ngSwitch和FromController的源代码中,您可以看到以下注释: // asks for $scope to fool the BC controller module 这是什么样的欺骗?为什么要用它 是向后兼容性的简写 加载此模块以启用旧式控制器,其中控制器和作用域混合在一起 此模块装饰Angular的$controller服务: 若给定的控制器不请求$scope,它将以旧的方式实例化它 若给定的控制器请求$scope,则实例化将委托给默认的$controller 服务

在指令ngSwitch和FromController的源代码中,您可以看到以下注释:

// asks for $scope to fool the BC controller module
这是什么样的欺骗?为什么要用它

向后兼容性
的简写

加载此模块以启用旧式控制器,其中控制器和作用域混合在一起

此模块装饰Angular的$controller服务:

  • 若给定的控制器不请求$scope,它将以旧的方式实例化它
  • 若给定的控制器请求$scope,则实例化将委托给默认的$controller 服务

    这也允许逐步迁移应用程序

因此,默认的angular模块总是请求
$scope
引用,即使它们不打算使用它,以避免为BC实例化

    // asks for $scope to fool the BC controller module
    controller: ['$scope', function ngSwitchController() {
     this.cases = {};
    }] ...
//asks for $scope to fool the BC controller module
FormController.$inject = ['$element', '$attrs', '$scope', '$animate'];
function FormController(element, attrs, $scope, $animate) {  ...