Callback or Promise #546
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
How do we get a call back within a component.
On upload of file I would like to access if success or error. On success, get filename and on error get error description.
This is what i have current (works great - thank you)
`export class UploadComponent implements OnInit {
public uploader: FileUploader = new FileUploader({url: URL});
public hasBaseDropZoneOver:boolean = false;
public hasAnotherDropZoneOver:boolean = false;
constructor() {
}
ngOnInit() {
}
public fileOverBase(e:any):void {
this.hasBaseDropZoneOver = e;
}
public fileOverAnother(e:any):void {
this.hasAnotherDropZoneOver = e;
}
}
`
You can hook into various events, something like this;
See here for various events you can hook into.
https://github.com/valor-software/ng2-file-upload/blob/development/components/file-upload/file-uploader.class.ts#L203
Regards,
Thank you! i'll give it a whirl :-)
@retrospectacus Do you know how I can get access to my
thiscontext from inside that event function? Since it isn't a callback, it seems like the function is not running in my components context, but in the FileUploader's context. Therefor I do not have access to any of my component's variables or functions.You can create a reference to
thisoutside of the function. It is a fairly common hack around these kind of issues and is usually calledself:HTH
Thank you, that will work. But shouldn't these events be handled with observables and not hacks? I can work on a solution and make a pull request if you are down with that. Should also add these events to the documentation.
This package doesn't seem to be using Observables, I'm not sure if there is a reason for that (reduce dependencies?). I am not a maintainer but they do seem to be open to pull requests. I submitted one recently that was merged.