Front-end - What is the difference between $scope and scope in angularjs
天蓬老师
天蓬老师 2017-05-15 16:55:58
0
2
711

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

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
習慣沉默

$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

大家讲道理

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template