1
+ ## Breaking changes
2
+ Input file repository dropped.
3
+ See below how to upload a file.
4
+
1
5
# ngx-input-file
2
6
3
7
** ngx-input-file** is a module to replace the html element input file and also allows you to upload files.
4
8
Style is based on [ Bootstrap File Input] ( http://plugins.krajee.com/file-input/demo ) .
5
- The component is compatible with [ Bootstrap 4 beta ] ( https://getbootstrap.com/ ) .
9
+ The component is compatible with [ Bootstrap 4] ( https://getbootstrap.com/ ) .
6
10
7
11
![ Input File screenshot] ( http://img4.hostingpics.net/pics/626115inputfile1.png )
8
12
@@ -13,35 +17,24 @@ The component is compatible with [Bootstrap 4 beta](https://getbootstrap.com/).
13
17
- Drag and drop zone
14
18
- Responsive
15
19
- [ Font Awesome] ( http://fontawesome.io/ ) support
16
- - Uploads files with headers like ` Authorization ` (deprecated, other modules uploads files better than this one)
17
20
18
21
## Installation
19
22
``` bash
20
23
npm install ngx-input-file --save
21
24
```
22
25
23
- ## Basic Configuration (deprecated)
24
- The goal of this module is not to upload file but to provide a component to replace the html element input.
25
- Create a new ` ngx-input-file.module.ts ` file with the following code:
26
- ``` ts
26
+ ## Basic Configuration
27
+ ``` typescript
27
28
import { NgModule } from ' @angular/core' ;
28
- import { InputFileModule , InputFileOptions , InputFileRepository } from ' ngx-input-file' ;
29
+ import { InputFileModule } from ' ngx-input-file' ;
29
30
30
- const options: InputFileOptions = new InputFileOptions (
31
- ' auth-token-value' ,
32
- ' Authorization'
33
- );
34
31
35
32
@NgModule ({
36
33
imports: [ InputFileModule ],
37
34
exports: [ InputFileModule ]
38
35
})
39
36
40
- export class NgxInputFileModule {
41
- constructor (private repository : InputFileRepository ) {
42
- repository .setOptions (options );
43
- }
44
- }
37
+ export class MyModule {}
45
38
```
46
39
Import this module in your module.
47
40
@@ -104,24 +97,29 @@ To add an other type, please open a issue.
104
97
(removedFile) =" onRemoveImage($event)" >
105
98
</input-file >
106
99
```
107
-
100
+ Here's an example to post a file:
108
101
``` ts
109
- import { InputFileRepository } from ' ngx-input-file ' ;
102
+ import { HttpClient } from ' @angular/common/http ' ;
110
103
111
- constructor (
112
- public inputFileRepository : InputFileRepository )
113
- {}
104
+ @Injectable ()
105
+ export class MyRepository {
114
106
115
- public post (file : any ): Observable < Image > {
116
- const apiUrl = ' http://dumb.any/api/files' ;
117
- return this.inputFileRepository.post(file , apiUrl);
107
+ constructor (
108
+ private http : HttpClient
109
+ ) {}
110
+
111
+ public post(file : any ): Observable <any > {
112
+ const apiUrl = ' my-url' ;
113
+ const formData = new FormData ();
114
+ formData .append (' file' , file .file , file .file .name );
115
+ return this .http .post (apiUrl , formData )
116
+ .map (res => <any >res );
118
117
}
119
118
` ` `
120
119
121
120
## IMPORTANT!
122
121
Icons is not packaged with the module.
123
122
Default path of file icons is ` assets / img ` with the extension ` .png ` .
124
- Please use [ @angular/cli ] ( https://cli.angular.io/ ) , ` ng new ... ` manages the folder ` assets ` .
125
123
Any help is welcome to package icons or configure the path and extension.
126
124
You can pick icons free [here](https://www.iconfinder.com/search?q=File&license=2&price=free).
127
125
0 commit comments