2017-02-28 29 views
0

角的1.4.x在SELECT

角最接近孩子在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

正如averything别的角度:修改模型,并采用NG-类添加基于模型的类。如果你发布了真实的代码,它会更容易帮助。 –

回答

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="[email protected]" 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>