-
Notifications
You must be signed in to change notification settings - Fork 26
/
image-validation.component.ts
42 lines (32 loc) · 1.19 KB
/
image-validation.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Component } from '@angular/core';
import { Ng2FileDropAcceptedFile } from 'ng2-file-drop';
@Component({
moduleId: __filename,
selector: 'image-validation',
templateUrl: 'image-validation.component.html',
styleUrls: ['image-validation.component.css'],
})
export class ImageValidationComponent {
/* tslint:disable:no-unused-variable */
// Supported image types
private supportedFileTypes: string[] = ['image/png', 'image/jpeg', 'image/gif'];
/* tslint:enable:no-unused-variable */
private imageShown: boolean = false;
private currentProfileImage: string = 'assets/profile-placeholder.png';
//
// File being dragged has been dropped and is valid
//
/* tslint:disable:no-unused-variable */
private dragFileAccepted(acceptedFile: Ng2FileDropAcceptedFile) {
/* tslint:enable:no-unused-variable */
// Load the image in
let fileReader = new FileReader();
fileReader.onload = () => {
// Set and show the image
this.currentProfileImage = fileReader.result;
this.imageShown = true;
};
// Read in the file
fileReader.readAsDataURL(acceptedFile.file);
}
}