AngularJS and papaParse Integration

2019-06-09 01:20发布

问题:

My form is this

<form name="form-basic" class="form-validation" ng-submit="uploadFile(updFrm.file)">
<input type="file" class="form-control" name="filee" id="files" ng-model="updFrm.file"/>
<input type="submit" value="click" class="btn btn-default">
</form>

I want to Pass Value of Input "file" into papaParse

Papa.parse(fileInput.files[0], {
    complete: function(results) {
        console.log(results);
    }
});

Now how to replace fileInput.files[0] with Value from " <input type="file" class="form-control" id="files" ng-model="updFrm.file"/>"

Please guide...

回答1:

Try to Change $scope.updFrm.file instead of fileInput.files[0]

//Or

in your function via

$scope.uploadFile = function(fileDetails)
{
  Papa.parse(fileDetails, {
    complete: function(results) {
        console.log(results);
    }
 });
}