【发布时间】:2015-09-13 09:47:57
【问题描述】:
我正在使用 ng-repeat 在 div 内的 html 页面上显示一些数据。在div 内部我有一个按钮,用于分别隐藏每个div 的内容。这是我的html 文件的简化版本。
<body ng-app="task" ng-controller="repeat">
<div ng-repeat='x in array' ng-show="{{ x.show }}">
<p>{{ x.text }}
</p>
<button ng-click="toggle()">Hide</button>
</div>
</body>
我的.js文件中的代码如下
var app = angular.module('task');
app.controller('repeat',function($scope){
$scope.array = [{
show: true,
text:'Sample Text 1'},
{
show: true,
text:'Sample Text 2'},
{
show: true,
text:'Sample Text 3'}];
$scope.toggle = function(){
$scope.array.show = false ;
};
})
任何人都可以建议我进行所需的更改,以便在单击我的 div 内的按钮时,该特定 div 会被隐藏。
我认为我在通过 ng-click 调用 function toggle() 时引用数组的特定元素时犯了一个错误
【问题讨论】:
标签: angularjs ng-repeat ng-show