PapaParse with Angular JS

Liked the good CSV parser and unpaired dad. Can anyone help me get this harvester with Angular JS.

I love making PapaParse work in the Angular Way. An attempt at a solution.

+2


source to share


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


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


just use front-end to modulate, for example requirejs

to load papaParser into context and call api in any of your controller or service.

0


source


Just enter script url in index.html

and then in your controller, access as - var Papa = window.Papa;

. It! You are ready for further action!

0


source







All Articles