Created
July 14, 2025 08:19
-
-
Save debugmodedotnet/90454b86beb18306b758b1d14b6985b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, signal } from '@angular/core'; | |
interface LightColor { | |
id: number; | |
name: string; | |
hex: string; | |
} | |
const template = ` | |
<h1>light demo </h1> | |
<div [style.backgroundColor]= 'color().hex' | |
[style.height.px]="height" | |
[style.width.px]="width"> | |
hello | |
</div> | |
` | |
@Component({ | |
selector: 'app-root', | |
template : template | |
}) | |
export class App implements OnInit { | |
protected title = 'light demo'; | |
height = 100; | |
width = 100; | |
lightColors: LightColor[] = [ | |
{ id: 0, name: 'Red', hex: '#FF0000' }, | |
{ id: 1, name: 'Yellow', hex: '#FFFF00' }, | |
{ id: 2, name: 'Green', hex: '#00FF00' } | |
] | |
color = signal(this.lightColors[0]); | |
constructor(){ | |
setInterval(() => { | |
if (this.color().id === 0) { | |
this.color.set(this.lightColors[1]); | |
setTimeout(() => { | |
this.color.set(this.lightColors[2]); | |
}, 5000); | |
} | |
else if (this.color().id === 2) { | |
this.color.set(this.lightColors[1]); | |
setTimeout(() => { | |
this.color.set(this.lightColors[0]); | |
}, 5000); | |
} | |
}, 10000); | |
} | |
ngOnInit(): void { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment