I'm trying to use ng-style to set the z-index and left margin of each item in my list. The list items are presented as cards and when they are stacked they are meant to look like stacked cards.
For z-index
- Count Intervention Cards
- Give top card a z-index equal to the total number of cards.
- The other cards should have a z-index one number lower than the one above it.
For margin-left
- Each card should have a margin-left 5px more than the one above it.
Heres' how it all looks:
Stacked (looks like crap) https://i.stack.imgur.com/WRVO4.png
But should looks like this https://i.stack.imgur.com/4MnvR.png
I've tried writing a function to set the z-index but it's not working. I'm probably way off.
Controller
(function() {
'use strict';
angular
.module('casemanagerApp')
.controller('CasePlanGoalsCtrl', CasePlanGoalsCtrl);
function CasePlanGoalsCtrl(lodash, Restangular, getDomainsResolve, getGoalsResolve, getInterventionsResolve) {
var vm = this;
var _ = lodash;
// Injections
vm.domains = getDomainsResolve;
vm.allGoals = getGoalsResolve;
vm.allInterventions = getInterventionsResolve;
// Functions
vm.domainInterventionCount = domainInterventionCount;
angular.forEach(vm.domainInterventionCount, function (value, key, card) {
var i = 1;
card.zIndex = {'z-index' : i++};
});
function domainInterventionCount(goalId) {
return _.size(_.filter(vm.allInterventions, {'goalId': goalId}));
}
}
})();
View
<!-- This is inside an ng-repeat-->
<div class="card" ng-style="card.zIndex()">
...
</div>