2015-12-23 38 views

回答

0

納克。在我的模板「ng-repeat(productList中的item)」中我使用了以下內容,注意你的重複將需要使用「track by $ index」語法:

<div ng-class="{ 'no' : 'image_off', 'yes': 'image_on' }[item.isOn]" ng-click="switchOnOff($index, item.productId, item.isOn); $event.stopPropagation();"></div> 

注意:「$ event.stopPropagation()」會阻止頁面提交。

「image_off/image_on」是指我的樣式表下的兩個不同的類。每個都有各自的背景圖像。

在你的控制器使用以下方法來操作的功能e.g「switchOnOff」裏面有關於UI事件:

$scope.productList[index].isOn = $scope.productList[index].isOn == 'no' ? 'yes' : 'no';