File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1111 </ mat-form-field >
1212
1313 < button mat-mini-fab color ="primary " class ="upload-btn "
14- (click) ="fileUpload.click() ">
14+ (click) ="onClick(fileUpload) " [disabled] =" disabled ">
1515 < mat-icon > attach_file</ mat-icon >
1616
1717 </ button >
Original file line number Diff line number Diff line change @@ -21,10 +21,21 @@ export class FileUploadComponent implements ControlValueAccessor {
2121
2222 uploadProgress :number ;
2323
24+ onChange = ( fileName :string ) => { } ;
25+
26+ onTouched = ( ) => { } ;
27+
28+ disabled : boolean = false ;
29+
2430 constructor ( private http : HttpClient ) {
2531
2632 }
2733
34+ onClick ( fileUpload : HTMLInputElement ) {
35+ this . onTouched ( ) ;
36+ fileUpload . click ( ) ;
37+ }
38+
2839 onFileSelected ( event ) {
2940
3041 const file :File = event . target . files [ 0 ] ;
@@ -56,6 +67,10 @@ export class FileUploadComponent implements ControlValueAccessor {
5667 if ( event . type == HttpEventType . UploadProgress ) {
5768 this . uploadProgress = Math . round ( 100 * ( event . loaded / event . total ) ) ;
5869 }
70+ else if ( event . type == HttpEventType . Response ) {
71+ this . onChange ( this . fileName ) ;
72+
73+ }
5974 } ) ;
6075
6176
@@ -64,6 +79,23 @@ export class FileUploadComponent implements ControlValueAccessor {
6479
6580 }
6681
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+
6799}
68100
69101
You can’t perform that action at this time.
0 commit comments