Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm migrating an existing project over to AngularJS and struggling to adapt the working JQuery File Upload code I wrote to the AngularJS paradigm.

Here's the working JQuery File Upload code I want to migrate into an Angular controller (in Coffeescript):

  $("#new_attachment").fileupload
    url: '/api/v1/attachments'
    dataType: 'json'
    add: (e, data) ->
      types = /(\.|\/)(gif|jpe?g|png|tif?f|pdf)$/i
      file = data.files[0]
      if types.test(file.type) || types.test(file.name)
        data.context = $(tmpl("template-upload", file))
        $('#attachments').append(data.context)
        data.submit()
      else
        alert("#{file.name} is not a format we currently support.")
    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.meter').css('width', progress + '%')
    done: (e, data) ->
      $('#attachments').append $(tmpl("template-thumbnail", data.files[0]))
      if data.context
        data.context.hide()
    fail: (e, data) ->
      alert "Upload failed on one or more images."  

Beyond injecting the fileupload module into the angular app (angular.module('demo', ['blueimp.fileupload'])), I pretty much stumped at how to bring this code into an Angular controller.

Any advice on how to approach this?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.