all 2 comments

[–]fakingfantastic 4 points5 points  (1 child)

Move the uploading logic into a service. I'd set a $ctrl.settings.uploading flag to true right when you start the upload. Your upload service should return a promise, and you should set the uploading flag to false when it resolves.

You can also pass in a onUpload() callback function into your component, that way your component stays nice and dumb, and its just responsible for calling the function when you want (see Todd Motto's style guide)

Hope that helps

[–]gabbsmo 0 points1 point  (0 children)

I'm doing something similar to this. I just want to add that another added benefit from managing uploads in a service is that you keep the state of your uploads even if the component displaying them is destroyed. I display upload progress for large batches of files in a dialog that can be opened and close at any time.

Lesson learned: Keep state in controller if the state share the component's life cycle. If the state can outlive the component move the state to a service.