Skip to content

Commit 4150f06

Browse files
committed
refactor: use new @if() control flow syntax
1 parent 21cdafb commit 4150f06

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed
Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
<button
2-
*ngIf="annotation"
3-
class="annotation-parent"
4-
[style.border-color]="annotation.color"
5-
[style.background-color]="annotation.color"
6-
(click)="clickAnnotation(annotation)"
7-
>
8-
<span class="annotation-content">
9-
<pre>{{ annotation.text }}</pre>
10-
</span>
1+
@if (annotation) {
2+
<button
3+
class="annotation-parent"
4+
[style.border-color]="annotation.color"
5+
[style.background-color]="annotation.color"
6+
(click)="clickAnnotation(annotation)"
7+
>
8+
<span class="annotation-content">
9+
<pre>{{ annotation.text }}</pre>
10+
</span>
1111

12-
<!-- Instead of setting the property "innerText" of this HTML element, we set "data-label". In CSS, we can then
12+
<!-- Instead of setting the property "innerText" of this HTML element, we set "data-label". In CSS, we can then
1313
reference the content of this property and can use the CSS pseudo- element "::after" to insert the content
1414
of "data-label" as text into the DOM. What's the advantage of this? At first, I tried to use the "innerText"
1515
property of this HTML element to visualize the annotation's label. Whenever the user selected a range of the
1616
original text, then the labels of the annotations were counted into the range, too. This made it difficult to
1717
extract which text range the user actually selected. By using the CSS pseudo-class "::after", we can prevent
1818
the annotations' labels from being included into the selected text range. -->
1919

20-
<span class="annotation-label" [attr.data-label]="annotation.label" [style.background-color]="annotation.color">
21-
</span>
22-
23-
<span class="annotation-button" *ngIf="removable">
24-
<span>
25-
<button
26-
class="remove-annotation"
27-
(click)="removeAnnotation(annotation)"
28-
aria-label="remove annotation"
29-
></button>
20+
<span class="annotation-label" [attr.data-label]="annotation.label" [style.background-color]="annotation.color">
3021
</span>
31-
</span>
32-
</button>
22+
23+
@if (removable) {
24+
<span class="annotation-button">
25+
<span>
26+
<button
27+
class="remove-annotation"
28+
(click)="removeAnnotation(annotation)"
29+
aria-label="remove annotation"
30+
></button>
31+
</span>
32+
</span>
33+
}
34+
</button>
35+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NgModule } from '@angular/core';
2-
import { CommonModule, NgComponentOutlet } from '@angular/common';
2+
import { NgComponentOutlet } from '@angular/common';
33
import { NgxAnnotationRendererComponent } from './components/annotation-renderer/annotation-renderer.components';
44
import { NgxAnnotateTextComponent } from './components/ngx-annotate-text/ngx-annotate-text.component';
55

66
@NgModule({
77
declarations: [],
8-
imports: [CommonModule, NgComponentOutlet, NgxAnnotationRendererComponent, NgxAnnotateTextComponent],
8+
imports: [NgComponentOutlet, NgxAnnotationRendererComponent, NgxAnnotateTextComponent],
99
exports: [NgxAnnotationRendererComponent, NgxAnnotateTextComponent],
1010
})
1111
export class NgxAnnotateTextModule {}

0 commit comments

Comments
 (0)