kimo
kimo

Reputation: 1904

Ng Repeat doesn't show data from array of dates in the web page

ng repeat on array of dates doesn't show the data in the web page, notice that when I set direct data into the array without loop it works: enter image description here
In this code I'm converting string date to an object then I create array of dates, increasing the date in 1 day in each iteration:

         //dates for table
            //convert date to object to allow me do action on it like increase the date in the table
            var startDate = $scope.tripById[0].start_date;
            var dateInNumberFormat = new Date(startDate).getTime();
            //create array for the dates to show it on table, each cell will have 1 extra day
            var day = 1000 * 3600 * 24; //day in miliseconds 1000 * 3600 = hour
            $scope.dates[0] = new Date(dateInNumberFormat + day);
            for(var i = 1; i < daysSum ; i++){
                day = 1000 * 3600 * (i * 24);
                $scope.dates[daysSum] = new Date(dateInNumberFormat + day);
                console.log($scope.dates[daysSum]);
            }

here is the ng-repeat:

  <table ng-table="usersTable" class="table table-striped" style="text-align: center;">

            <tr>
                <td>Date</td>
                <td ng-repeat="date in dates track by $index">{{date}}</td>
            </tr>

Why ng repeat on my array doesn't show me the dates in the web page?

Upvotes: 0

Views: 240

Answers (1)

Majid Yaghouti
Majid Yaghouti

Reputation: 913

In loop you put all dates in the same index. Change it as:

for(var i = 1; i < daysSum ; i++){
    day = 1000 * 3600 * (i * 24);
    $scope.dates[i] = new Date(dateInNumberFormat + day);
    console.log($scope.dates[i]);
}

Upvotes: 1

Related Questions