0

I'm creating a scheduler/calendar, but I have to built my own from scratch.

I have an array of days per month. For example May: 31 days. Now I want to seperate that array into weeks, and then display using a table. (like a calendar)

Please take into consideration that later on, I will have to make these 'days' clickable to be able to perform further actions on them.

What I tried:

I tried to do a nested array weeks[week_number][day_number]. However when trying to show the days the following code does not work at all. It shows nothing.

<tr *ngFor="let week of weeks; let i = index">
<td *ngFor="let day of week.days; let j = index "> {{ day }}</td>

I have looked up StackOverflow but could not find anything.

8
  • 1
    change the tag cause this isnt angular 1.x Commented May 13, 2017 at 21:06
  • you have to make use of pipes , Angular pipes for displaying nested data in a json, can you post the json data . for reference stackoverflow.com/questions/35705424/… Commented May 13, 2017 at 21:06
  • Check this plunker: plnkr.co/edit/96JrD09Xn9whEhup2Atr?p=preview Do you have a data structure like this? Commented May 13, 2017 at 21:23
  • @echonax I think not. its an array weeks that consists of four days arrays right? Commented May 13, 2017 at 21:25
  • @sadboy yep. What does your array looks like, can you provide it in your question? Commented May 13, 2017 at 21:26

2 Answers 2

0

If you're using a 2D Array, how are you expecting to access the days in the week using week.days?

Doing let week of weeks in the first *ngFor means that the week variable is now equal to a 1D array of days (a.k.a. weeks[i]).

Therefore your nested loop should simply be let day of week instead of let day of week.days.

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

Comments

0

// First you have to loop through each 'week' Object:

<tr *ngFor="let week of weeks">

// Then you have to loop through each 'day' Object of the child Array of Objects that are containing your days

<td *ngFor="let day of week.days"> {{ day.name }}</td>

// {{ day.name }} represents your 'name' Object property if exists ( it may be used under different convention )

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.