mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-12 13:53:03 -05:00
feat(challenge33): about performance
This commit is contained in:
23
libs/shared/directives/src/lib/cd-flashing.directive.ts
Normal file
23
libs/shared/directives/src/lib/cd-flashing.directive.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/* eslint-disable @angular-eslint/directive-selector */
|
||||
import { Directive, DoCheck, ElementRef, NgZone } from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: '[cd-flash]',
|
||||
standalone: true,
|
||||
})
|
||||
export class CDFlashingDirective implements DoCheck {
|
||||
constructor(private elementRef: ElementRef, private zone: NgZone) {}
|
||||
|
||||
ngDoCheck(): void {
|
||||
this.cdRan();
|
||||
}
|
||||
|
||||
public cdRan(): void {
|
||||
this.zone.runOutsideAngular(() => {
|
||||
this.elementRef.nativeElement.classList.add('!bg-orange-500');
|
||||
setTimeout(() => {
|
||||
this.elementRef.nativeElement.classList.remove('!bg-orange-500');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user