search

Home  >  Q&A  >  body text

Front-end - What is the difference between $scope and scope in angularjs

I have always had a question in the process of learning angularjs, what is the difference between $scope and scope?

天蓬老师天蓬老师2810 days ago738

reply all(2)I'll reply

  • 習慣沉默

    習慣沉默2017-05-15 16:57:58

    $scope is a variable provided internally by angular.

    scopeGenerally refers to concepts such as scope directive service and so on.

    In terms of variables

    function($scope){
    
    }
    
    function(scope){
    
    }
    

    No difference.

    But the scope or $scope object above is an object provided internally by angular. We usually obtain this object through dependency injection. If you display dependencies:

    app.controller("MainCtrl",["$scope",function(scopeObject){
    
    }]);
    

    The injected variable name must be $scope, and the formal parameters in the function do not matter.

    If it is implicit injection,

    app.controller("MainCtrl",function($scope){
    
    });
    

    The function parameter must be $scope

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-15 16:57:58

    Following the answer above, the implicitly injected code

    app.controller("MainCtrl",function($scope){
    
    });

    $scope can be injected through implicit injection, but when compressing js code, variable names are usually replaced with abbreviations such as abc, causing implicit injection to fail. Therefore, display injection is generally used. At this point, whether to use $scope or scope becomes part of the coding specification, and there is no difference.

    reply
    0
  • Cancelreply