import "zone.js"; import { bootstrapApplication } from "@angular/platform-browser"; import { Component, Input, EventEmitter, Output, OnInit } from "@angular/core"; import { NgIf } from "@angular/common"; @Component({ selector: "file-date", standalone: true, template: `{{ dateStr }}`, }) class FileDateComponent implements OnInit { @Input() inputDate!: Date; /** * You cannot access `Input` data from the root (constructor) * of the class */ dateStr = ""; labelText = ""; ngOnInit() { this.dateStr = this.formatDate(this.inputDate); this.labelText = this.formatReadableDate(this.inputDate); } formatDate(inputDate: Date) { // Month starts at 0, annoyingly const monthNum = inputDate.getMonth() + 1; const dateNum = inputDate.getDate(); const yearNum = inputDate.getFullYear(); return monthNum + "/" + dateNum + "/" + yearNum; } dateSuffix(dayNumber: number) { const lastDigit = dayNumber % 10; if (lastDigit == 1 && dayNumber != 11) { return dayNumber + "st"; } if (lastDigit == 2 && dayNumber != 12) { return dayNumber + "nd"; } if (lastDigit == 3 && dayNumber != 13) { return dayNumber + "rd"; } return dayNumber + "th"; } formatReadableDate(inputDate: Date) { const months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; const monthStr = months[inputDate.getMonth()]; const dateSuffixStr = this.dateSuffix(inputDate.getDate()); const yearNum = inputDate.getFullYear(); return monthStr + " " + dateSuffixStr + "," + yearNum; } } @Component({ selector: "file-item", standalone: true, imports: [NgIf, FileDateComponent], template: ` `, }) class FileComponent { @Input() fileName!: string; @Input() href!: string; @Input() isSelected!: boolean; @Input() isFolder!: boolean; @Output() selected = new EventEmitter(); inputDate = new Date(); } @Component({ selector: "file-list", standalone: true, imports: [FileComponent], template: ` `, }) class FileListComponent {} bootstrapApplication(FileListComponent);