• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / #55

30 Jul 2025 07:08AM UTC coverage: 9.866% (-80.4%) from 90.297%
#55

push

why520crazy
feat(empty): add setMessage for update display text #TINFR-2616

92 of 6794 branches covered (1.35%)

Branch coverage included in aggregate %.

2014 of 14552 relevant lines covered (13.84%)

6.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.76
/src/input/input-count.component.ts
1
import { Component, OnInit, ChangeDetectionStrategy, inject, DestroyRef, input, effect, signal } from '@angular/core';
2
import { ThyInputDirective } from './input.directive';
3
import { switchMap, filter, tap } from 'rxjs/operators';
4
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
5
import { Subject } from 'rxjs';
6
import { ThyInputGroup } from './input-group.component';
7

8
/**
9
 * 输入框输入文字展示
10
 * @name thy-input-count
11
 * @order 40
12
 */
13
@Component({
1✔
14
    selector: 'thy-input-count',
15
    template: '{{inputLength()}} / {{maxLength()}}',
×
16
    changeDetection: ChangeDetectionStrategy.OnPush,
×
17
    host: {
×
18
        class: 'thy-input-count text-muted'
×
19
    }
×
20
})
×
21
export class ThyInputCount implements OnInit {
×
22
    private inputGroup = inject(ThyInputGroup, { optional: true })!;
×
23

×
24
    private readonly destroyRef = inject(DestroyRef);
×
25

×
26
    private hasInput = false;
×
27

×
28
    /**
29
     * 输入框组件,如果不传默认会读取外层 thy-input-group 下的 thyInput 指令
30
     * @type ThyInputDirective
31
     */
32
    readonly thyInput = input<ThyInputDirective>();
×
33

34
    maxLength = signal<number | string>(undefined);
×
35

36
    inputLength = signal(0);
×
37

38
    thyInput$ = new Subject<ThyInputDirective>();
×
39

40
    constructor() {
×
41
        this.setup();
42

43
        effect(() => {
44
            const input = this.thyInput();
45
            if (input) {
×
46
                this.hasInput = true;
×
47
                this.thyInput$.next(input);
×
48
            }
49
        });
50
    }
1✔
51

1✔
52
    setup() {
53
        this.thyInput$
54
            .pipe(
55
                filter(input => {
1✔
56
                    return !!input;
57
                }),
58
                tap(input => {
59
                    this.maxLength.set(input.nativeElement.getAttribute('maxlength'));
60
                }),
61
                takeUntilDestroyed(this.destroyRef),
62
                switchMap(input => {
63
                    return input.ngControl.valueChanges;
64
                }),
65
                tap(value => {
66
                    this.inputLength.set(value?.length || 0);
67
                }),
68
                takeUntilDestroyed(this.destroyRef)
69
            )
70
            .subscribe();
71
    }
72

73
    ngOnInit(): void {
74
        const inputDirective = this.inputGroup.inputDirective();
75
        if (!this.hasInput && this.inputGroup && inputDirective) {
76
            this.thyInput$.next(inputDirective);
77
        }
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc