ohayolibs
Version:
Ohayo is a set of essential modules for ohayojp.
36 lines (30 loc) • 1.12 kB
text/typescript
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation } from '@angular/core';
import addSeconds from 'date-fns/addSeconds';
import format from 'date-fns/format';
import { CountdownComponent, CountdownConfig, CountdownEvent } from 'ngx-countdown';
({
selector: 'count-down',
exportAs: 'countDown',
template: ` <countdown #cd *ngIf="config" [config]="config" (event)="handleEvent($event)"></countdown> `,
preserveWhitespaces: false,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
})
export class CountDownComponent {
('cd', { static: false }) readonly instance: CountdownComponent;
() config: CountdownConfig;
/**
* 目标时间
*/
()
set target(value: number | Date) {
this.config = {
format: `HH:mm:ss`,
stopTime: typeof value === 'number' ? addSeconds(new Date(), value).valueOf() : +format(value, 't'),
};
}
() readonly event = new EventEmitter<CountdownEvent>();
handleEvent(e: CountdownEvent): void {
this.event.emit(e);
}
}