【发布时间】:2015-12-16 16:13:21
【问题描述】:
一系列链接apple, orange, banana 是使用ng-repeat 创建的。点击这些链接会导致该水果的颜色出现在链接下方。
问题:但是,当点击任何链接时,所有水果的颜色都会显示出来。我们如何限制点击事件只显示被点击的水果的颜色?
Jsfiddle: http://jsfiddle.net/hut13fox/
HTML
<div ng-controller="FruitCtrl">
<div ng-repeat="f in fruits">
<a href="#" ng-click="toggleShow()">{{ f.title }}</a>
<div ng-show="show">
{{ f.color }}
</div>
</div>
</div>
JS
var myApp = angular.module('myApp', []);
FruitCtrl = function($scope) {
$scope.fruits = [
{ title: 'apple', color: 'red' },
{ title: 'orange', color: 'orange' },
{ title: 'banana', color: 'yellow' }
];
$scope.show = false
$scope.toggleShow = toggleShow
function toggleShow() {
console.log('toggle')
$scope.show = !$scope.show
}
}
console.log('Hello')
【问题讨论】:
标签: javascript jquery html angularjs