Add a resend-code cooldown to the OTP screen

Angular · Angular · intermediate · greenfield

Adds the resend button with its cooldown as a small signal machine: the remaining seconds live in a signal, and an effect schedules one `setTimeout` per tick, cleaning it up via the effect's `onCleanup` hook. Uses the `output()` function API for the event, so there's no `@Output()` decorator or EventEmitter import. A visually-hidden status region announces once when resending is available again.

Requirements

Files touched

--- src/app/auth/resend-code.component.ts
+import { Component, effect, output, signal } from '@angular/core';
+
+@Component({
+  selector: 'app-resend-code',
+  standalone: true,
+  template: `
+    <button type="button" (click)="resend()" [disabled]="cooldown() > 0">
+      @if (cooldown() > 0) {
+        Resend code in {{ cooldown() }}s
+      } @else {
+        Resend code
+      }
+    </button>
+    <span class="visually-hidden" role="status">
+      @if (requested() && cooldown() === 0) {
+        You can request a new code now.
+      }
+    </span>
+  `,
+  styles: `
+    .visually-hidden {
+      position: absolute;
+      width: 1px;
+      height: 1px;
+      overflow: hidden;
+      clip-path: inset(50%);
+      white-space: nowrap;
+    }
+  `,

Review this PR

Angular practice