In the source code of the directive ngSwitch and FromController you can see this comment:
// asks for $scope to fool the BC controller module
what kind of cheating is it? why is it used?
// 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) { ...
The BC controller module is shorthand for Backward Compatability.
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.
So, the default angular modules always ask for the $scope reference even if they do not intend to use it, to avoid being instantiated for BC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With