1

I need to pass a data-attribute to an angular controller function. (I'm sure there's a better name, but the context is below):

Dropzone.js has a "preview template". For every file you upload in the dropzone, it renders the HTML you specify here.

Here's a part of this HTML which is of interest:

    <div class="dz-size"><span data-dz-size></span></div>
    <div class="dz-filename"><span data-dz-name></span></div>

I would like to do something like:

<div class="dz-filename"><span data-dz-name></span></div>
<i class="fa" class="{{getIconFromFilename(dz-name)}}" style="..."></i>    

Does anyone know the proper syntax for this?

2 Answers 2

1

I found complex angular directive for Dropzone here

You can catch file after upload a then set proper class name in Your scope

$scope.dropzoneConfig = {
'options': { // passed into the Dropzone constructor
  'url': 'upload.php'
},
'eventHandlers': {
  'sending': function (file, xhr, formData) {
  },
  'success': function (file, response) {
     // set scope icon class from file
  }
}};
Sign up to request clarification or add additional context in comments.

2 Comments

I've thought about this. Scope is shared across multiple file uploads, though. So I would still have a problem when trying to find the appropriate file/index in the preview template.
Actually, solved it this way. Note that for everyone looking to do the same thing, you'll probably be needing to use $compile to create a scope per file upload. stackoverflow.com/questions/32905136/…
0

What you need is the ng-class directive.
Depending on what your function returns this may work:

<i class="fa" ng-class="[getIconFromFilename(dz-name)]"></i>   

2 Comments

Could you provide a JSFiddle / Plnkr link with the code? what is dz-name meant to represent?
dropzonejs.com, upload a file, right click on filename and view source

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.