Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asks for $scope to fool the BC controller module

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?

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) {  ...
like image 436
rnrneverdies Avatar asked Dec 05 '25 02:12

rnrneverdies


1 Answers

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.

like image 106
Claies Avatar answered Dec 07 '25 08:12

Claies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!