Skip to content

Commit e87783e

Browse files
Merge pull request #41 from jacobbutton/master
Multiple File-Drops
2 parents 929a6b4 + 71b2a8c commit e87783e

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/lib/ngx-drop/file-drop.component.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ export class FileComponent implements OnDestroy {
3232
dragoverflag: boolean = false;
3333

3434
constructor(private zone: NgZone) {
35-
window['angularComponentRef'] = {
36-
zone: this.zone,
37-
traverseFileTree: (item, path) => this.traverseFileTree(item, path),
38-
addToQueue: (item) => this.addToQueue(item),
39-
pushToStack: (str) => this.pushToStack(str),
40-
popToStack: () => this.popToStack(),
41-
component: this
42-
};
4335
if (!this.customstyle) {
4436
this.customstyle = 'drop-zone';
4537
}
@@ -123,33 +115,34 @@ export class FileComponent implements OnDestroy {
123115
if (item.isFile) {
124116
const toUpload: UploadFile = new UploadFile(path, item);
125117
this.files.push(toUpload);
126-
window['angularComponentRef'].zone.run(() => {
127-
window['angularComponentRef'].popToStack();
118+
this.zone.run(() => {
119+
this.popToStack();
128120
});
129121
} else {
130122
this.pushToStack(path);
131123
path = path + '/';
132124
const dirReader = item.createReader();
133125
let entries = [];
126+
const thisObj = this;
134127

135128
const readEntries = function () {
136129
dirReader.readEntries(function (res) {
137130
if (!res.length) {
138131
// add empty folders
139132
if (entries.length === 0) {
140133
const toUpload: UploadFile = new UploadFile(path, item);
141-
window['angularComponentRef'].zone.run(() => {
142-
window['angularComponentRef'].addToQueue(toUpload);
134+
thisObj.zone.run(() => {
135+
thisObj.addToQueue(toUpload);
143136
});
144137
} else {
145138
for (let i = 0; i < entries.length; i++) {
146-
window['angularComponentRef'].zone.run(() => {
147-
window['angularComponentRef'].traverseFileTree(entries[i], path + entries[i].name);
139+
thisObj.zone.run(() => {
140+
thisObj.traverseFileTree(entries[i], path + entries[i].name);
148141
});
149142
}
150143
}
151-
window['angularComponentRef'].zone.run(() => {
152-
window['angularComponentRef'].popToStack();
144+
thisObj.zone.run(() => {
145+
thisObj.popToStack();
153146
});
154147
} else {
155148
// continue with the reading

0 commit comments

Comments
 (0)