Monday, August 15, 2016

AngularJS: Integrate with Papa Parse

I was trying to write a Web app to parse .csv file with Papa Parse and AngularJS. The first problem I ran into was that ng-model does not support input[file]. Luckily, custom directive come to rescue!

The second problem was that, I was unable to access the value of my custom directive within my controller's scope. I was able to resolve it by creating a custom object to hold the value.

The third problem was that, after parsing the .csv file, I would update the result in my controller, but the changes were not being reflected in HTML. Since Papa Parse is not AngularJS aware or verse versa, I need to notify AngularJS about the changes by wrapping my update logic within $scope.$apply().


Ref:
angularjs - ng-model for <input type="file"/> - Stack Overflow
AngularJS and scope.$apply — Jim Hoskins
AngularJS: API: input

No comments: