gpt4 book ai didi

angularjs - 要求 $scope 来欺骗 BC Controller 模块

转载 作者:行者123 更新时间:2023-12-02 03:32:43 25 4
gpt4 key购买 nike

在指令 ngSwitch 和 FromController 的源代码中你可以看到这样的注释:

// asks for $scope to fool the BC controller module

这是什么作弊行为?为什么使用它?

ngSwitch Source Line

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

FormController Soruce Line

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

最佳答案

BC controller moduleBackward Compatibility 的简写。

Load this module to enable old-style controllers, where controller and scope are mixed together.

This module decorates Angular's $controller service:

  • if given controller does not ask for $scope, it instantiates it in old-way
  • if given controller does ask for $scope, instantiation is delegated to default $controller service.

    This also allows migrating apps step by step.

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

关于angularjs - 要求 $scope 来欺骗 BC Controller 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25716714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com