DEV Community

Cover image for Angular: How to build a full screen calendar like Outlook

Angular: How to build a full screen calendar like Outlook

Ricky Stam on May 07, 2020

In an Angular project a while back I needed to display a full screen calendar like the one in outlook. So as a good lazy developer I start looking ...
Collapse
 
bryannativel profile image
bryanNativel

Thanks for your solution

Collapse
 
gencatcree profile image
Genji

Good job!

Collapse
 
rickystam profile image
Ricky Stam

Thank you :)

Collapse
 
herrigor profile image
herrigor

This piece of code here is so cool

weekDays.push(days)
if (++index % chunkSize === 0) {
calendarDays.push(weekDays);
weekDays = [];
}

Collapse
 
rickystam profile image
Ricky Stam

Thank you herrigor, I hope you find it useful :)

Collapse
 
kahiko profile image
Kahiko

Thank you for your post it was very helpful. I added a method to determine the exact number of days for the number day in the calendar instead of 42 in generateCalendarDays and thought I would pass it on:
/**

  • Calculates the number of calendar days in a given month. *
  • @param {Date} day - The date used to determine the month.
  • @return {number} The number of calendar days in the specified month. */ private getNumberOfCalendarDays(day: Date): number { const mYear = day.getFullYear(); const mMonth = day.getMonth()+ 1; const mFristDay = new Date(mYear, mMonth, 1).getDay(); const mLastDay = new Date(mYear, mMonth + 1, 0).getDay(); const mDaysFromLastMonth = mFristDay - 1 == -1 ? 6 : mFristDay - 1; const mDaysFromNextMonth = 6 - mLastDay == -1 ? 0 : 6 - mLastDay; const mDaysInMonth = new Date(mYear, mMonth + 1, 0).getDate(); return (mDaysFromLastMonth + mDaysInMonth + mDaysFromNextMonth) + 1; }
Collapse
 
donhmorris profile image
Don Morris

Looks good man

Collapse
 
rickystam profile image
Ricky Stam

Thank you Don, glad you like it!

Collapse
 
santoshyadavdev profile image
Santosh Yadav

This is amazing 🎉🎉

Collapse
 
thisdotmedia_staff profile image
This Dot Media

You did great Ricky!

Collapse
 
rickystam profile image
Ricky Stam

Many thanks :)

Collapse
 
spock123 profile image
Lars Rye Jeppesen

Very nice

Collapse
 
surajkurade profile image
surajKurade

Hi Ricky. It's awesome. Just wanted to know why we use map instead of foreach in pipe. Am new in angular

Collapse
 
rickystam profile image
Ricky Stam • Edited

Hi surajKurade!

For this example it wouldn't make any difference to be honest. Map and ForEach both iterate the array and apply the given function, their difference is that ForEach doesn't return a value just iterates the array and executes the given function on the elements but map will return a new array with the modified array.

Usually people are using map when they want to achieve immutability (they don't want to modify their array but to return a modified copy)

Example:

let nums = [1,2,3];
let result = nums.forEach(n => n*2); // here the result variable will be undefined
let result = nums.map(n => n*2) // here the result variable will be [2, 4, 6]

Hope this helps!

Collapse
 
surajkurade profile image
surajKurade

Thanks Ricky 👍

Collapse
 
pkhussain profile image
pkhussain

Hi Ricky, Can we create room and meeting booking in your good calendar ?

Collapse
 
rickystam profile image
Ricky Stam

Hi @pkhussain sure you can use it as you like :) Just keep in mind that this is just a POC and might have bugs, I've never tested it thoroughly, so use with causion!

Collapse
 
harigovindyadv profile image
hari govind yadav

Great help!! Thanks :-)

Collapse
 
nadiagizdova profile image
Nadia Gizdova • Edited

Hi there! I'm looking at your implementation but It currently seems like the left and right arrows are skipping/incorrectly setting the months. Do you know why this might be happening?

Collapse
 
bizzareadventure profile image
bizzareadventure

Thank you for the code,

Is there any hint to like Monday, Tuesday, etc it in datatable?

I have difficulty to match the day just like on the calendar