0

I am getting data in nested array.

I am trying to display my data in this format

Jan

01 Mon newyear
13 sat bhogi
14 sun pongal

Feb

14 tue Valentine's day

Am little bit confused to loop it.

This is what I have tried

<table ng-repeat="list in holidayList" style="width:100%">
                            <thead>
                                <tr>
                                    @*<th>{{list.}}</th>*@
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="leave in list">
                                    <td width="14%">{{leave.date}}</td>
                                    <td width="20%">{{leave.monthCode}}</td>
                                    <td>{{leave.holiday_name}}</td>
                                </tr>
                            </tbody>
                        </table>

Converting date is doesn't matter I wrote custom filter and method for that so I can get expected date format by using this filter and method:

app.filter('jsonDate', function () {
    return function (date) {
        return new Date(date.match(/\d+/)[0] * 1);
    }
})

$scope.dateFormat = function (date) {
        $scope.formattedDate = date.getFullYear() + "-" + (((date.getMonth() + 1).length) == 2 ? (date.getMonth() + 1) : ("0" + (date.getMonth() + 1))) + "-" + ((date.getDay().length) == 2 ? date.getDay() : ("0" + date.getDay()));
        return $scope.formattedDate
    }

Current output:

/Date(1484397151447)/   1   pongal
/Date(1484310751447)/   1   Bhogi
/Date(1483273951447)/   1   new year
/Date(1494855933060)/   5   may day

Can any one tell me that how should I loop to get expected format.

3
  • can you able to post your data Commented Dec 6, 2017 at 4:04
  • What are you currently getting for the output? Commented Dec 6, 2017 at 4:06
  • @nipuna777 check updated post. Commented Dec 6, 2017 at 4:08

1 Answer 1

3

You could just directly access the object: (I am assuming that the month is defined in each array item)

<table ng-repeat="list in holidayList" style="width:100%">
    <tbody>
        <tr>
            <td>{{list[0].month}}</td>
        </td>
        <tr ng-repeat="leave in list">
            <td width="14%">{{leave.date}}</td>
            <td width="20%">{{leave.monthCode}}</td>
            <td>{{leave.holiday_name}}</td>
        </tr>
    </tbody>
</table>

If month is not defined then use javascript array for months:

$scope.months = ["Jan", "February, "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

Then on your html:

<td>{{months(list[0].monthCode - 1)}}</td>

or just list[0].monthCode if monthCode starts with 0 for Jan.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.