如何解决如何将 dropzone 结果添加到 angularjs 输入?
在我的 Angular 应用程序中,我使用 DropzoneJs 在 ng-repeater 字段中上传图像,一切正常我可以将图像上传到我的服务器,我可以获得 Json 结果,但我需要将上传的图像 ID 添加到角度输入值,
这里是我的角度代码
Dropzone.autoDiscover = false;
var app = angular.module('dropzone',[]);
app.directive('dropzone',function() {
return function(scope,element,attrs) {
var config,dropzone;
config = scope[attrs.dropzone];
// create a Dropzone for the element with the given options
dropzone = new Dropzone(element[0],config.options);
// bind the given event handlers
angular.forEach(config.eventHandlers,function(handler,event) {
dropzone.on(event,handler);
});
};
});
angular.module('plunker',['ui.sortable','dropzone']);
angular.module('plunker').controller('MyCtrl',['$scope',function($scope) {
$scope.inputs = [{
choices: ''
}];
$scope.addInput = function() {
$scope.inputs.push({
choices: ''
});
}
$scope.dropzoneConfig = {
options: {
'url': 'upload.php',init: function() {
this.on("success",function(file,response) {
var e = JSON.parse(response);
console.log("sent" + e.location);
$scope.inputs.img = e.location;
});
}
},}
}]);
这里是html代码;
<div class="inputArea" ng-controller="MyCtrl" ng-app="plunker">
<div ui-sortable="sortableOptions" ng-model="inputs" >
<div ng-repeat="input in inputs" >
<div ng-model="input.files" id="dropzone1" class="dropzone " dropzone="dropzoneConfig" ng-dropzone></div>
<label for="imgid">ImageID:</label>
<input id="imgid" type="text" ng-model="input.files.img" name="out[{{$index+1}}][img]" autocomplete="off"/>
<p></p>
<label for="desc">Description:</label>
<textarea id="desc" type="textarea" name="out[{{$index+1}}][desc]"></textarea>
</div>
</div>
<div class="add-poll" ng-click="addInput()">add input</div>
</div>
我试过了;
$scope.inputs.img = e.location;
但不工作,这里Plunker
感谢您的回答。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。