Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9250303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:24:54+00:00 2026-06-18T10:24:54+00:00

Trying to create a file upload directive using jQuery File Upload plugin and this

  • 0

Trying to create a file upload directive using jQuery File Upload plugin and this gist of the directive https://gist.github.com/thoughtpalette/4726114

I need to pass in a id from an object in profile-ctrl.js into the submit functionality for the upload form.

My Directive lies outside of the controller and I couldn’t set the object to $rootScope to catch/pass it in the directive.

the url: in fileupload is where the magic happens. Calling my controller via an api and passing over the file information and hopefully the vendorId which is in the merchant object in profile-ctrl.js. $scope.merchant

I cannot post in a fiddle due to the project structure unfortunately

My Directive:

//jqueryFileUpload-Plugin 
//https://github.com/blueimp/jQuery-File-Upload
define(['jquery',
        'angular',
        'core',
        'source/core/helpers/urlHelper.js'],
    function ($, angular, core, urlHelper) {
    "use strict";
    return [ function ($compile) {
        return {
            restrict:'E',
            scope: {
                merchant: '=ngModel'
            },
            compile:function(el,attrs, scope){
                var compiler = this,
                elem = el,
                vendorId = scope.merchant.id;
                instanceFn = function() {
                    var currentScope = this,
                        fileInputDiv = $(' <span class="btn btn-success fileinput-button">'+
                        '<i class="icon-plus icon-white"></i>'+
                        '<span>Upload Logo</span>'+
                        '<input type="file" name="files[]" single>'+
                        '</span>').appendTo(elem),
                        fileInput = fileInputDiv.find('input'),
                        fileList = $('<div class="UploaderList">'+
                        '<table>'+
                        '<tr>'+
                        '<td>File to Upload</td>'+
                        '</tr>'+
                        '</table>'+
                        '</div>').appendTo(elem),
                        button = $('<button class="btn">Submit</button>').appendTo(elem);

                    button.hide();
                    $('<div class="uploader">').appendTo(elem);
                    $('</div>').appendTo(elem);

                    fileInput.fileupload({
                        url:urlHelper.vendor.uploadLogo(vendorId),
                        dataType: 'json',
                        add:function (e, data) {

                            button.show();

                            // this will add a handler which will submit this specific file
                            button.bind('click.uploadsubmit', function(){ 
                                data.submit();
                            });
                            $.each(data.files, function (index, file) {
                                $("<tr><td>"+file.name+"</td><td></td><tr>").appendTo(fileList.find('table:first'));
                            });
                        },
                        // for each file
                        done: function (e, data) {

                            button.hide();

                            var result = "",
                                r = data.result,
                                file = data.files[0]; // we only support single file upload by now
                            // error

                            // CHANGE THIS PART FOR YOUR REQUIREMENTS (I have a json repsonse)

                            if(r.success !== undefined && r.success === false){
                                result = "<span class='error'>Unknown error</span>";
                                if(r.errors !== undefined && r.errors.length > 0 && r.errors[0].message !== undefined)
                                {
                                    result = "<span class='error'>"+r.errors[0].message+"</span>";
                                }
                            }
                            else{
                                result = "<span class='success'>OK</span>";
                            }

                            $("td:contains('"+file.name+"')").next().html(result);
                        },
                        progressall:function (e, data) {
                            var progress = parseInt(data.loaded / data.total * 100, 10);
                        },
                        // called only once... (wen submit button is clicked)
                        start:function(e){

                            // we start the upload, so we do also cleanup jobs right now:
                            button.unbind('click.uploadsubmit'); // importan - remove all event handlers
                            button.hide();
                            fileInputDiv.hide();

                        }
                    });

                };
                return instanceFn;
            }

        };
    }]; 
});

Directive Call via html:

<jquery-File-Upload ng-model="merchant"></jquery-File-Upload>

So right now merchant returns undefined in the directive. Can someone help me pass that in?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:24:56+00:00Added an answer on June 18, 2026 at 10:24 am

    As mentioned in the comments, the 3rd argument to the compile function isn’t the scope, its a transclude linking function. Here’s an example of how to use that, if you’re curious.

    The instanceFn you define is your linking function, since it is being returned by the compile function. The first argument to the linking function is the scope, and merchant should be defined on it.

    Trying $watch()ing merchant, then execute your logic once you notice a change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a multiple file upload scenario based on blueimp ( http://blueimp.github.com/jQuery-File-Upload )
I'm trying to create file upload using iframe(ajax effect) but I need to know
I am using this upload file example . And I am trying to modify
I'm using the jQuery File Upload plugin (documentation here ) integrated into my Rails
js.I am trying to create a file upload using node.js and mongodb.I am getting
I'm trying to create a simple file upload form for my website. I'm using
I am trying to create a PHP file to upload images to my website.
I am trying to upload a file with playframework. I create a form and
Im trying to create new file on D: drive with c/c++ I found this
I am trying to create a file using File newFile = new File(myFile); However

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.