File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 11
11
</ mat-form-field >
12
12
13
13
< button mat-mini-fab color ="primary " class ="upload-btn "
14
- (click) ="fileUpload.click() ">
14
+ (click) ="onClick(fileUpload) " [disabled] =" disabled ">
15
15
< mat-icon > attach_file</ mat-icon >
16
16
17
17
</ button >
Original file line number Diff line number Diff line change @@ -21,10 +21,21 @@ export class FileUploadComponent implements ControlValueAccessor {
21
21
22
22
uploadProgress :number ;
23
23
24
+ onChange = ( fileName :string ) => { } ;
25
+
26
+ onTouched = ( ) => { } ;
27
+
28
+ disabled : boolean = false ;
29
+
24
30
constructor ( private http : HttpClient ) {
25
31
26
32
}
27
33
34
+ onClick ( fileUpload : HTMLInputElement ) {
35
+ this . onTouched ( ) ;
36
+ fileUpload . click ( ) ;
37
+ }
38
+
28
39
onFileSelected ( event ) {
29
40
30
41
const file :File = event . target . files [ 0 ] ;
@@ -56,6 +67,10 @@ export class FileUploadComponent implements ControlValueAccessor {
56
67
if ( event . type == HttpEventType . UploadProgress ) {
57
68
this . uploadProgress = Math . round ( 100 * ( event . loaded / event . total ) ) ;
58
69
}
70
+ else if ( event . type == HttpEventType . Response ) {
71
+ this . onChange ( this . fileName ) ;
72
+
73
+ }
59
74
} ) ;
60
75
61
76
@@ -64,6 +79,23 @@ export class FileUploadComponent implements ControlValueAccessor {
64
79
65
80
}
66
81
82
+ writeValue ( value : any ) {
83
+ this . fileName = value ;
84
+ }
85
+
86
+ registerOnChange ( onChange : any ) {
87
+ this . onChange = onChange ;
88
+ }
89
+
90
+ registerOnTouched ( onTouched : any ) {
91
+ this . onTouched = onTouched ;
92
+ }
93
+
94
+ setDisabledState ( disabled : boolean ) {
95
+ this . disabled = disabled ;
96
+ }
97
+
98
+
67
99
}
68
100
69
101
You can’t perform that action at this time.
0 commit comments