In HTML, I want to display multiple rows of items(tasks timeline). In each row, gantt-items,gantt-days is used to plot 365 small boxes which are presented 365 days in a year. And each row need to display a blue block, which means the assigned period of this task. {{timeline(item.data.sDate,item.data.eDate)}}, each row only contains one blue block.
HTML
<ul>
<li ng-repeat="item in items.entities">
<ul class="gantt-items" style="width: 9150px; height: 35px" >
<li class="gantt-item" >
<ul class="gantt-days">
</ul>
</li>
</ul>
{{timeline(item.data.sDate,item.data.eDate)}}
</li>
</ul>
JS
angular.module('myApp', ['ngResource']);
function MainCtrl($scope,$resource){
$(document).ready(function(){
...
for(var i = 1; i < 366; i++){
$(".gantt-item ul.gantt-days").append('<li class="gantt-day" style="width: 25px"><span style="line-height: 35px; height: 35px">' + year + "-" + d.getMonth() + "-" + d.getDate() + '</span></li>');
d = new Date(d.getTime() + (24 * 60 * 60 * 1000));
}
...});
$scope.timeline = function GetLength(startDate, endDate){
var firstDay = new Date(new Date().getFullYear(), 0, 1);
var st1 = startDate.split("/");
var dt1 = new Date(st1[2], st1[1] - 1, st1[0]);
var st2 = endDate.split("/");
var dt2 = new Date(st2[2], st2[1] - 1, st2[0]);
var startPoint = ((dt1.getTime() - firstDay.getTime())/1000/60/60/24)*25;
var length = (1+(dt2.getTime() - dt1.getTime())/1000/60/60/24)*25;
$(".gantt-item ul.gantt-days").append('<span class="gantt-block" style="left:' + startPoint + 'px; width: ' + length + 'px; height: 27px"><strong class="gantt-block-label">Duration</strong></span>');
};
When I am using ng-repeat, $(".gantt-item ul.gantt-days").append doesn't work. And timeline(item.data.sDate,item.data.eDate) is repeating n times in each row, which supposes to show only one item per raw of n rows.
It happens because the elements in the ng-repeat directive appear after the DOM compiling.
Try using $watch:
$scope.$watch('items.entities', function(){
for(var i = 1; i < 366; i++){
$(".gantt-item ul.gantt-days").append('<li class="gantt-day" style="width: 25px"><span style="line-height: 35px; height: 35px">' + year + "-" + d.getMonth() + "-" + d.getDate() + '</span></li>');
d = new Date(d.getTime() + (24 * 60 * 60 * 1000));
}
});