我是angular js的新手。我想使用此文件上传。
我用下面的链接
http://jsfiddle.net/jasonals/WEvwz/27/?
upload.html
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://blueimp.github.com/jQuery-File-Upload/js/vendor/jquery.ui.widget.js"></script>
<script src="http://blueimp.github.com/jQuery-File-Upload/js/jquery.fileupload.js"></script>
<div ng-controller='TestCtrl'>
<div>
<input id="fileupload" type="file" name="files[]" data-url="/" multiple>
<ul>
<li ng-repeat="file in fileList">
{{file.name}}
</li>
</ul>
</div>
<button ng-click='addButtonClicked()'>Add File</button>
</div>
controlller file.
$(document).ready(function(){
$('#fileupload').fileupload({
dataType: 'json'});
});
TestCtrl = function($scope){
$scope.fileList = [];
$('#fileupload').bind('fileuploadadd', function(e, data){
// Add the files to the list
numFiles = $scope.fileList.length
for (var i=0; i < data.files.length; ++i) {
var file = data.files[i];
// .$apply to update angular when something else makes changes
$scope.$apply(
$scope.fileList.push({name: file.name})
);
}
// Begin upload immediately
data.submit();
});
$scope.addButtonClicked = function(){
var numFiles = $scope.fileList.length;
$scope.fileList.push({name: ('fileName' + numFiles)});
}
}
但我无法使用此发布网址。
最佳答案
试试这个...
$(document).ready(function(){
$('#fileupload').fileupload({
dataType: 'json'});
});
TestCtrl = function($scope){
$scope.fileList = [];
$('#fileupload').bind('fileuploadadd', function(e, data){
$scope.$apply(
$scope.fileList.push({name: file.name})
);
data.submit();
});
}
关于jquery - Angular Js文件上传,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20393725/