I am just diving into the world of AngularJS, so this assignment is a great learning opportunity for me. I understand that my approach may not be perfect or exactly what you are looking for. Please review and let me know if there is room for improvement.
Currently, I have tackled this task by creating two distinct CSS classes with the only variance being the background color.
You could organize the background colors into separate classes and simply toggle between them while keeping everything else constant.
HTML
<div ng-app ng-controller="testCtrl" >
<div ng-repeat="item in items">
<div ng-class="item.class" ng-click="select(item)">{{item.text}}</div>
</div>
</div>
JS
function testCtrl($scope) {
$scope.items = [
{ text:'List item 1', class:'default normal' },
{ text:'List Item 2', class:'default normal' },
{ text:'List Item 3', class:'default normal' }
];
$scope.select = function(item) {
angular.forEach($scope.items, function (value, key) {
if(value == item) {
value.class = 'default select' // selected
}
else {
value.class = 'default normal' // restored
}
});
};
}
CSS
.default { font-size: 25px; padding: 10px; margin-bottom: 5px; }
.normal { background: yellow; }
.select { background: cyan; }
Check out the JSFiddle demonstration here.