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

atinc / ngx-tethys / 5fa9630c-19a1-4ee7-af3d-6a0c3535952a

08 Oct 2024 08:24AM UTC coverage: 90.438% (+0.007%) from 90.431%
5fa9630c-19a1-4ee7-af3d-6a0c3535952a

push

circleci

minlovehua
refactor: refactor all control-flow directives to new control-flow #TINFR-381

5511 of 6738 branches covered (81.79%)

Branch coverage included in aggregate %.

98 of 104 new or added lines in 58 files covered. (94.23%)

113 existing lines in 17 files now uncovered.

13253 of 14010 relevant lines covered (94.6%)

991.73 hits per line

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

90.63
/src/anchor/anchor-link.component.ts
1
import { Platform } from '@angular/cdk/platform';
2
import {
3
    ChangeDetectionStrategy,
4
    Component,
5
    ContentChild,
6
    ElementRef,
7
    Input,
8
    OnDestroy,
9
    OnInit,
10
    TemplateRef,
11
    ViewChild,
1✔
12
    ViewEncapsulation
13
} from '@angular/core';
49✔
14
import { useHostRenderer } from '@tethys/cdk/dom';
1✔
15

1✔
16
import { ThyAnchor } from './anchor.component';
17
import { NgTemplateOutlet } from '@angular/common';
18

48✔
19
/**
20
 * 锚点链接组件,可供锚点跳转
21
 * @name thy-anchor-link,thyAnchorLink
22
 */
48✔
23
@Component({
48✔
24
    selector: 'thy-link,thy-anchor-link',
48✔
25
    exportAs: 'thyLink,thyAnchorLink',
48✔
26
    preserveWhitespaces: false,
48✔
27
    template: `
48✔
28
        <a #linkTitle (click)="goToClick($event)" href="{{ thyHref }}" class="thy-anchor-link-title" title="{{ title }}">
48✔
29
            @if (title) {
48!
NEW
30
                <span>{{ title }}</span>
×
31
            } @else {
32
                <ng-template [ngTemplateOutlet]="titleTemplate || thyTemplate"></ng-template>
33
            }
34
        </a>
48✔
35
        <ng-content></ng-content>
36
    `,
37
    encapsulation: ViewEncapsulation.None,
7✔
38
    changeDetection: ChangeDetectionStrategy.OnPush,
39
    standalone: true,
40
    imports: [NgTemplateOutlet]
7✔
41
})
42
export class ThyAnchorLink implements OnInit, OnDestroy {
43
    title: string | null = '';
26✔
44

45
    titleTemplate?: TemplateRef<any>;
46

3✔
47
    private hostRenderer = useHostRenderer();
3✔
48

3!
49
    /**
3✔
50
     * 锚点链接
51
     */
52
    @Input() thyHref = '#';
53

48✔
54
    /**
55
     * 文字内容
1✔
56
     */
57
    @Input()
58
    set thyTitle(value: string | TemplateRef<void>) {
59
        if (value instanceof TemplateRef) {
60
            this.title = null;
1✔
61
            this.titleTemplate = value;
62
        } else {
63
            this.title = value;
64
        }
65
    }
66

67
    @ContentChild('thyTemplate') thyTemplate!: TemplateRef<void>;
1✔
68

69
    @ViewChild('linkTitle', { static: true }) linkTitle!: ElementRef<HTMLAnchorElement>;
70

71
    constructor(
72
        public elementRef: ElementRef,
73
        private anchorComponent: ThyAnchor,
74
        private platform: Platform
75
    ) {
76
        this.hostRenderer.addClass('thy-anchor-link');
77
        if (elementRef.nativeElement.tagName.toLowerCase() === 'thy-link') {
78
            console.warn(`'thy-link' and 'thyLink' are deprecated, please use 'thy-anchor-link' and 'thyAnchorLink' instead.`);
79
        }
80
    }
81

82
    ngOnInit(): void {
83
        this.anchorComponent.registerLink(this);
84
    }
85

86
    getLinkTitleElement(): HTMLAnchorElement {
87
        return this.linkTitle.nativeElement;
88
    }
89

90
    setActive(): void {
91
        this.hostRenderer.addClass('thy-anchor-link-active');
92
    }
93

94
    unsetActive(): void {
95
        this.hostRenderer.removeClass('thy-anchor-link-active');
96
    }
97

98
    goToClick(e: Event): void {
99
        e.preventDefault();
100
        e.stopPropagation();
101
        if (this.platform.isBrowser) {
102
            this.anchorComponent.handleScrollTo(this);
103
        }
104
    }
105

106
    ngOnDestroy(): void {
107
        this.anchorComponent.unregisterLink(this);
108
    }
109
}
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