import { CommonModule } from "@angular/common"; import { Component, input, type OnInit, signal } from "@angular/core"; import AstroLogo from "../../images/astro.png?url"; import OutSystemsLogo from "../../images/outsystems.png?url"; import { Operation, setCounterCount } from "../../lib/setCounterCount"; @Component({ imports: [CommonModule], selector: "app-counter", standalone: true, template: `
Angular Demo Component
Angular counter component
Internal counter controls. It keeps state within the component.
{{ count() }}
The button sends the current count value to a function in the parent component.
Nano Stores (not supported)
Slot content (not supported)
OutSystems logo Astro logo
`, }) export default class DemoComponent implements OnInit { astroLogo = AstroLogo; count = signal(0); initialCount = input(0, { alias: "initialCount" }); messageFunctionName = input("", { alias: "showMessage" }); outSystemsLogo = OutSystemsLogo; add() { this.count.update((i) => setCounterCount(i, Operation.Add)); } ngOnInit() { this.count.set(this.initialCount()); } showParentMessage() { const fnName = this.messageFunctionName(); // Safety check to ensure the function exists on window. // eslint-disable-next-line @typescript-eslint/no-explicit-any if (typeof (window as any)[fnName] === "function") { // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any)[fnName](this.count()); } } subtract() { this.count.update((i) => setCounterCount(i, Operation.Subtract)); } }