动态改变ng重复
dynamically change ng-repeat
我有一个这样的对象:
var examples = {
'example1': {
ex1: {},
ex2: {},
ex3: {}
},
'example2': {
ex1: {},
ex2: {},
ex3: {}
}
}
有一个按钮链接到一个函数,该函数在第一次单击时用值填充example1对象,在第二次单击时使用值填充example2对象。
- 首先点击:example1获取值
- 第二次点击:example2获取值
然后我使用ng重复遍历对象,如下所示:
data-ng-repeat="example in examples.example1.ex1"
data-ng-repeat="example in examples.example1.ex2"
data-ng-repeat="example in examples.example1.ex3"
这里的问题是,当第二次单击按钮时,我需要ng repeat以某种方式更改和循环example2对象。所以我的问题是,有没有一种方法可以动态地改变ng重复?
编辑:目标是在第一次单击后显示的第一个列表,然后在第二次单击后同时显示的两个列表。
我试图制作一个值为2的$scope,并将其放入ng repeat中,但没有成功。
$scope.counter = 2; //in a controller
data-ng-repeat="example in examples.example(counter).ex1"
使用动态属性名称
$scope.prop = 'example1';
$scope.click = function (newProp) {
$scope.prop = newProp;
// do whatever you want here
// change prop to example2 or
// or simply toggle Boolean to change prop text
}
在html中使用
ng-repeat="example in examples[prop].ex1"
是否可以通过"examples"进行循环,然后在ng repeat中包含一个ng重复?
类似这样的东西:
<div data-ng-repeat="example in examples">
<div data-ng-repeat="ext in example">
{{ext.ex1}} {{ext.ex2}} {{ext.ex3}}
</div>
</div>
在html中做一些类似Jannik的回答,在JS:中做一些这样的事情
$scope.examples = {};
function example(exes) {
this.exes = exes;
}
$scope.onClick = function(exes) {
$scope.examples.push(new example(exes));
}
exes是ex1、ex2等的列表。您可能需要一个$scope$apply()来更新UI。
相关文章:
- 角度:在ng重复上切换图像
- AngularJS:ng之后,重复$scope值未按预期更新
- 列出每行2个元素的最佳方式是按角度重复ng
- 访问重复之外的ng重复ng形式
- 将我的列表 vom ng-repeat 更改为收集重复 ng-click 后,无法正常工作
- 如何隐藏 ng 重复 ng 如果
- 在ng中指定变量,重复ng次单击
- 如果else为Angular,则使用ng click函数重复ng
- 选择特定键,然后显示特定值而不重复 ng 重复
- 将数据传递给指令,以便在指令内重复 ng
- 在两行(或更多行)上重复 ng
- 自动返回到结果的第一页,重复 ng
- AngularJS-在一级数组上重复ng的表
- AngularJS未捕获引用错误:ng重复ng单击
- 隐藏基于下拉列表中所选选项的输入值,ng重复ng隐藏
- 如何在Angular模板中设置变量,在第一个元素上重复ng
- 将数组值偏移一个数字,用于在引导程序列上重复ng
- angularjs ng如果不是空的,重复ng
- 使用具有多个重复ng的单选按钮组的ng-model
- 在表中重复ng和条件tr