Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  90] [ 1]  / answers: 1 / hits: 18024  / 7 Years ago, wed, may 31, 2017, 12:00:00

I have an Angular app that I want to use particles.js in however I have no clue how to add it and get it working.



I've added it to the .angular-cli.json



  scripts: [
../node_modules/particles.js/particles.js
],


And I've imported it into my component



import * as  particlesJS from 'particles.js';


And attempted to initialize it using



  particlesJS.load('particles-js', 'assets/particles.json', function() {
console.log('callback - particles.js config loaded');
});


Has anyone got this working?


More From » angular

 Answers
4

Here is how to do that:




  1. Just import the particles.js in your index.html (cdn or local)



    <script src=https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js></script>

  2. Put in the div anchor into your component template (you could also put it to index.html or somewhere else)



    <div id=particles-js></div>

  3. Make the package visible by adding a simple type definition (in your component or in the typings.d.ts)



    declare var particlesJS: any;

  4. Initialize it in ngOnInit (or somewhere else)



    particlesJS.load('particles-js', 'particles.json', null);



I have made a little plunker example:
http://plnkr.co/edit/GLRvYgNPJue4KqdMuAJB?p=preview


[#57605] Monday, May 29, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;