File tree 1 file changed +14
-1
lines changed
src/app/shared/components/copy-button
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 1
- import { Component , ElementRef , inject } from '@angular/core' ;
1
+ import {
2
+ Component ,
3
+ ElementRef ,
4
+ inject ,
5
+ ChangeDetectorRef ,
6
+ } from '@angular/core' ;
2
7
3
8
@Component ( {
4
9
selector : 'app-copy-button' ,
@@ -9,12 +14,20 @@ export class CopyButtonComponent {
9
14
public elRef = inject < ElementRef < HTMLElement > > ( ElementRef < HTMLElement > ) ;
10
15
public copied = false ;
11
16
17
+ public cdr = inject < ChangeDetectorRef > ( ChangeDetectorRef ) ;
18
+
12
19
onCopy ( ) {
13
20
const preRef = this . elRef . nativeElement . querySelector ( 'pre:not(.hide)' ) ;
14
21
if ( ! preRef ) {
15
22
return ;
16
23
}
17
24
navigator . clipboard . writeText ( preRef . firstChild . textContent ) ;
18
25
this . copied = true ;
26
+ this . cdr . detectChanges ( ) ;
27
+
28
+ setTimeout ( ( ) => {
29
+ this . copied = false ;
30
+ this . cdr . detectChanges ( ) ;
31
+ } , 2000 ) ;
19
32
}
20
33
}
You can’t perform that action at this time.
0 commit comments