Requests $ scope to trick BC controller module

In the source code of the ngSwitch and FromController directives, you can see this comment:

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

      

what is this deception? why is it used?

ngSwitch Source Line

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

      

Sort string FormController

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

      

+3


source to share


1 answer


BC Controller Module is short for Backward Compatability

.

Load this module to include old style controllers where controller and scope are blended together.

This module decorates the Angular $ controller service:

  • If the given controller does not request $ scope, it starts it in the old mode
  • if a given controller requests $ scope, the instance is delegated to the standard $ controller service.

    It also allows you to migrate applications step by step.



So, by default Angular modules always ask for a reference $scope

, even if they don't intend to use it, in order to avoid instantiating for BC.

+1


source