count-down 倒计时 - 图1 This article has not been translated, hope that your can PR to translated it. Help us!count-down 倒计时 - 图2

count-down 倒计时

倒计时组件,依赖 ngx-countdown

依赖

  1. yarn add ngx-countdown
  1. import { CountDownModule } from '@delon/abc/count-down';

代码演示

count-down 倒计时 - 图3

基本

简单的倒计时组件使用。

  1. import { Component } from '@angular/core';
  2. import { NzMessageService } from 'ng-zorro-antd/message';
  3. import { CountdownEvent } from 'ngx-countdown';
  4. @Component({
  5. selector: 'components-count-down-simple',
  6. template: `
  7. <div>
  8. <count-down #cd [target]="10" (event)="handleEvent($event)" style="font-size: 20px;"></count-down>
  9. </div>
  10. <button nz-button (click)="cd.instance.pause()">Pause</button>
  11. <button nz-button (click)="cd.instance.resume()">Resume</button>
  12. `,
  13. })
  14. export class ComponentsCountDownSimpleComponent {
  15. constructor(private msg: NzMessageService) {}
  16. handleEvent(e: CountdownEvent) {
  17. if (e.action === 'done') {
  18. this.msg.success('finised');
  19. }
  20. }
  21. }

count-down 倒计时 - 图4

精度

0.1s精度使用方式。

  1. import { Component } from '@angular/core';
  2. import { CountdownConfig } from 'ngx-countdown';
  3. @Component({
  4. selector: 'components-count-down-accuracy',
  5. template: `
  6. <count-down [config]="config"></count-down>
  7. `,
  8. })
  9. export class ComponentsCountDownAccuracyComponent {
  10. config: CountdownConfig = {
  11. format: `s.S`,
  12. leftTime: 30,
  13. };
  14. }

API

count-down

成员说明类型默认值
[target]目标时间,number 表示秒number | Date-
[config]完整 Config 参数CountdownConfig-
(event)事件通知EventEmitter<CountdownEvent>-