Angularjs 带索引的角度重复
我只想在单击“显示”按钮时显示此部分中的名称。我试图使用索引进行检测,但没有成功Angularjs 带索引的角度重复,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我只想在单击“显示”按钮时显示此部分中的名称。我试图使用索引进行检测,但没有成功 code: <div ng-repeat="c in customers"> <a ng-click="display(c.id[$index])" ng-hide="need to hide after click this one">{{vm.updateText}}</a> <div ng-show="c.id[$index]" class="updat
code
:
<div ng-repeat="c in customers">
<a ng-click="display(c.id[$index])" ng-hide="need to hide after click this one">{{vm.updateText}}</a>
<div ng-show="c.id[$index]" class="updateSection">
<input type="text" name="id" data-ng-model="id" />
<input type="button" ng-click="vm.veryId(id)" value="{{vm.verifyButtonText}}">
<input type="button" ng-click="vm.Cancel()" value="{{vm.cancelButtonText}}">
</div>
</div>
// will show ng-click="vm.veryId(id)"
<rpe-progress data-ng-show="vm.showProgress" block="true"></rpe-progress>
// if id is working will show following error message:
<rpe-alert show="vm.mpnIdAlert">{{vm.errormessage}}</rpe-alert>
<script>
vm.display= function (index) {
vm.id[index] = true;
// I want show updatesection & hide Update text
}
vm.cancel= function () {
// I want hide updatesection & show Update text
}
vm.veryId= function (id) {
// If id is wrong show error message.
}
</script>
{{vm.updateText}
//将显示ng click=“vm.veryId(id)”
//如果id正在工作,将显示以下错误消息:
{{vm.errormessage}
vm.display=函数(索引){
vm.id[index]=true;
//我想显示更新部分并隐藏更新文本
}
vm.cancel=函数(){
//我想要隐藏更新部分并显示更新文本
}
vm.veryId=函数(id){
//如果id错误,则显示错误消息。
}
如果我正确理解您的问题,您应该使用track by
例如:
<div ng-repeat="n in [42, 42, 43, 43] track by $index">
{{n}}
<p ng-show="$index === 3">Index is 3</p>
</div>
{{n}}
索引是3
在模板中没有不能做的事情,不需要该功能。您只需在该
项上切换一些show
属性即可
看看这个例子:
{{item.id}
{{item.name}
切换
如果不想切换,可以执行以下操作:
<button ng-click="item.show = true">show</button>
show
发布的逻辑@Pevara绝对正确。我建议你遵循这个逻辑
我不理解您的问题的实际用例。因此,如果您真的想用$index
值来完成这个逻辑,那么您可以使用下面的代码片段来完成您的任务
var-app=angular.module('app',[]);
应用控制器('indexCtrl',函数($scope){
$scope.customers=[
{姓名:'ABC',年龄:26},
{姓名:'DEF',年龄:32},
{姓名:'GHI',年龄:21}
];
$scope.toggleDisplay=函数(索引){
$scope.customers[index].show=!$scope.customers[index].show;
};
});代码>
名称
年龄
{{c.name}}
展示
{{c.Age}}
如果客户的对象数组本身包含名称,则传递对象本身,而不是传递$index
请看这里:
点击我
$scope.clickMe=函数(x){
$scope.selected=x;
}
这只是一个演示track By使用的示例,这只是示例代码,但我的代码有文本框和错误消息等。。。所以我试着用索引。我不明白你们为什么要把这类事情复杂化。。。您应该仍然能够将show
属性添加到customers
数组中的每个项目c
。保持简单易读。如果您愿意发布完整的代码,我很乐意将我的示例改编为您的用例。
<button ng-click="item.show = true">show</button>
<button ng-click="clickMe(x)">Click Me</button>
$scope.clickMe = function(x){
$scope.selected = x;
}