PapaParse with Angular JS
4 answers
You can use value
to provide standalone third party libraries.
angular.module('your.app')
.value('yourLib', yourLib);
Then in your controller or service you will inject it in the normal way using DI
angular.module('your.app')
.controller('YourController', YourController);
YourController.$inject = ['yourLib'];
function YourController(yourLib) {
//. . .
}
If the third party is a constructor function, it requires it to be new, you can create a factory or a provider that has a method that takes pass parameters to the constructor, returns a new instance.
Edit
Looking at PapaParse you want to register it with the angular injector using value
.
+4
source to share
I didn't really do anything to load it. Just add it to html file and to my lib folder. In my case: /lib/papaparse.min.js
and index.html. As usual script:
<script src="lib/papaparse.min.js"></script>
then i just used it in my controller:
Papa.parse(data, {
complete: function(results) {
console.log("Finished:", results.data);
}
});
+6
source to share