Angular 1.4.x
在ng-repeat
我有一个SELECT
控件,其下面有DIV
个详细信息。当SELECT
被更改时,我希望为DIV添加一个类。
BEGIN ng-repeat
<select ng-change="???add a class XYZ to .details ???">...</select>
<div class="details">...</div>
END
答案 0 :(得分:1)
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.selection = [];
$scope.isHighlighted = [];
$scope.items = [{
id: 1,
label: 'Label 1',
}, {
id: 2,
label: 'Label 2',
}];
$scope.selectionChanged = function(idx) {
$scope.isHighlighted[idx] = true;
}
});
.highlight {
color: red;
}
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.10/angular.js" data-semver="1.5.10"></script>
</head>
<body ng-controller="MainCtrl">
<div ng-repeat="item in items">
<select ng-options="item as item.label for item in items track by item.id" ng-model="selection[$index]" ng-change="selectionChanged($index)"></select>
<div ng-class="{highlight:isHighlighted[$index]}">Some Div Content</div>
</div>
</body>
</html>