如何在angularjs在NG-重复独特的范围 [英] how to have unique scope in ng-repeat in angularjs
问题描述
是否有可能对我来说,有$范围多个阵列?
Is it possible for me to have multiple array for $scope?
我有DIV与一个从NG-重复父范围产生子作用域列表。我怎么能有范围变量单独独特之处?
i have a list of div with child scopes that is generated from a parent scope in ng-repeat. How can i have the scope variable individually unique?
我生成在另一个NG-NG重复重复的列表。
I am generating a list of ng-repeat in another ng-repeat.
<div ng-repeat="" ng-init="hide=true" ng-click="hide=!hide">
<div ng-hide="hide" ng-init="childhide=true" ng-click="childhide=!childhide">
<div ng-repeat="" ng-init="childhide" ng-hide="childhide">
<div>{{ variable }}</div>
</div>
</div>
</div>
我怎么能有可变独特之处?当我点击任何一个分区,每次堂妹,与childhide变量的所有分区将显示。总之,使他们的个人行为?
How can i have the variable unique? Coz each time when i click on either one div, all div with childhide variable will show. Anyway to make them behave individually?
感谢。
推荐答案
要获得一个新的$范围为每个div,浮现在脑海的第一个婷是创建另一个指令,并指定你想要哪种类型的范围。
To get a new $scope for each div, the first ting that comes to mind is to create another directive and specify which type of scope you want.
<div class="container">
<div ng-repeat="item in items"></div>
</div>
将变为:
<div class="container">
<inner-directive ng-repeat="item in items"></inner-directive>
</div>
然后内指令:
app.directive('innerDirective', function () {
return {
restrict: 'E',
template: '<div></div>', // this replaces what you had before
scope: {}
};
});
这将创建一个分离的范围,从它的父不继承属性。
This will create an isolate scope, which does not inherit properties from it's parent.
有一对夫妇的其他范围选项,但我不记得把我的头了每个人做的顶部。容易在文档,虽然看的。
There are a couple of other scope options but i cant remember off the top of my head what each one does. Easy to read in the docs though.
这篇关于如何在angularjs在NG-重复独特的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!