Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJs input[type=file] bug
    text
    copied!<p>I want to handle file uploads using angularjs. I have settled up a model, view, controller and service that is included in the controller:</p> <pre><code>#Model window.App.factory 'RepositoryItem', (railsResourceFactory) -&gt; railsResourceFactory url: '/api/repository_items/{{_id &amp;&amp; _id.$oid}}' name: 'repository_item' </code></pre> <hr> <pre><code>#Service window.App.service 'fileUpload', (RepositoryItem) -&gt; this.files = {} this.remove = (field) =&gt; itemToRemove = field.value if (itemToRemove) field.value.remove().then -&gt; index = field.items.indexOf itemToRemove field.items.splice index, 1 field.value = field.items[0] this.init = (task, field) =&gt; # IT WORKS RepositoryItem.query({ realm: task.variables.realm, criterion:{taskId: task.id, formType: field.id} }).then (fileItems) =&gt; this.files[field.id] = fileItems this.upload = (task, field, element) =&gt; for file in element.files reader = new FileReader() reader.onload = (event) =&gt; # IT DOES NOT WORK new RepositoryItem({ formType: field.id, taskId: task.id, content: event.target.result, name: file.name }).create().then (newItem) =&gt; console.log 'newItem' console.log newItem this.rootScope.$apply =&gt; this.files[field.id].push newItem reader.readAsBinaryString file </code></pre> <hr> <pre><code>#View &lt;script type="text/ng-template" id="fileUpload"&gt; &lt;div class="field"&gt; &lt;table class='attachments' ng-init="fileUpload.init(task, f)"&gt; &lt;tr&gt; &lt;td&gt; Attachments &lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; {{ fileUpload.files }} &lt;tr ng-repeat="file in fileUpload.files[f.id]"&gt; &lt;td&gt; {{file.name}} &lt;/td&gt; &lt;td&gt; XXX &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="file" multiple onchange="angular.element(this).scope().fileUpload.upload({{task}}, {{f}}, this)"/&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p>and inside the upload method I make an attempt to create new RepositoryItem. This method should send request to the server (as it does in init action) but it does not send any request. How can I fix that?</p> <p><strong>upd1:</strong></p> <p>I have tracked nested calls of rails-angular-resource. It calls $http(config) but no request is tracked in network console nor by my server.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload