Javascript 有多少范围';在angularApp中有s
我的问题是,下面的代码中有多少范围元素,包括isolatedScope、$scope、$rootScopeJavascript 有多少范围';在angularApp中有s,javascript,angularjs,Javascript,Angularjs,我的问题是,下面的代码中有多少范围元素,包括isolatedScope、$scope、$rootScope <script> angular.module('initExample', []) .controller('ExampleController', ['$scope', function($scope) { $scope.list = [['a', 'b'], ['c', 'd']];
<script>
angular.module('initExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.list = [['a', 'b'], ['c', 'd']];
}]);
</script>
<body ng-app="myApp">
<div ng-controller="ExampleController">
<div ng-repeat="innerList in list" ng-init="outerIndex = $index">
<div ng-repeat="value in innerList" ng-init="innerIndex = $index">
<span class="example-init">list[ {{outerIndex}} ][ {{innerIndex}} ] = {{value}};</span>
</div>
</div>
</div>
</body>
angular.module('initExample',[])
.controller('ExampleController',['$scope',function$scope){
$scope.list=[[a'、[b']、[c'、[d'];
}]);
列表[{outerIndex}}][{{innerIndex}]={{{value}};
将有一个$rootScope
,
然后将有控制器范围
,来自示例控制器
然后,由于ng repeat
为每一行创建一个新的scope
,因此外部ng repeat
将创建list.length
作用域,ng init
不会创建新的作用域,
现在,内部ng repeat
为每个外部ng repeat
运行一次,因此它将为每个列表项创建innerList.length
范围
因此,总作用域将是:$rootScope
+$scope
来自Controller+列表。length
*innerList.length
所以在这个例子中,总数是1+1+2*2=6
(我不知道为什么需要这些信息,但这里有)
注意:您可以查看文档,了解哪个指令
S创建一个新的(独立的)范围
。
还要注意的是,如果innerList对每个列表项都有可变的长度,那么公式将包括innerList长度与outerlist长度之和,而不是直接乘法
i、 e,(1*i1+1*i2+…外部列表长度时间),其中i1、i2是内部列表长度,
然后将有控制器范围
,来自示例控制器
然后,由于ng repeat
为每一行创建一个新的scope
,因此外部ng repeat
将创建list.length
作用域,ng init
不会创建新的作用域,
现在,内部ng repeat
为每个外部ng repeat
运行一次,因此它将为每个列表项创建innerList.length
范围
因此,总作用域将是:$rootScope
+$scope
来自Controller+列表。length
*innerList.length
所以在这个例子中,总数是1+1+2*2=6
(我不知道为什么需要这些信息,但这里有)
注意:您可以查看文档,了解哪个指令
S创建一个新的(独立的)范围
。
还要注意的是,如果innerList对每个列表项都有可变的长度,那么公式将包括innerList长度与outerlist长度之和,而不是直接乘法
i、 e,(1*i1+1*i2+…外部列表长度时间),其中i1、i2是内部列表长度ng repeat不会为每一行创建一个隔离范围。每个指令都有自己的范围。2 ng重复=2scopes@gyc来自文档:ngRepeat指令对集合中的每个项实例化一次模板。每个模板实例都有自己的作用域感谢@gaurav5430以简单的方式解释了这一点:)ng repeat不会为每一行创建单独的作用域。每个指令都有自己的范围。2 ng重复=2scopes@gyc来自文档:ngRepeat指令对集合中的每个项实例化一次模板。每个模板实例都有自己的作用域感谢@gaurav5430以简单的方式解释了这一点:)ng repeat和ng init呢?ng repeat和ng init呢?